Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
function showTime()
{
let date = new Date();
let hours = date.getHours();
let minutes = date.getMinutes();
let seconds= date.getSeconds();

let formatHours = convertFormat(hours);

hours = checkTime(hours);

hours = addZero(hours);
minutes = addZero(minutes);
seconds = addZero(seconds);

document.getElementById('clock').innerHTML=`${hours} : ${minutes} : ${seconds} ${formatHours}`
}

function convertFormat(time)
{
let format ='AM';
if(time>=12)
{
format = 'PM';
}
return format;
}

function checkTime(time)
{
if(time>12)
{
time-=12;
}
if(time === 0)
{
time=12;
}
return time;
}

function addZero(time)
{
if(time<10)
{
time='0'+time;
}
return time;

}
showTime();
setInterval(showTime,1000);