-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (32 loc) · 1.4 KB
/
script.js
File metadata and controls
32 lines (32 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const hour=document.getElementById("hour");
const min=document.getElementById("min");
const sec=document.getElementById("sec");
const day=document.getElementById("day");
const date=document.getElementById("date");
const month=document.getElementById("month");
const format=document.getElementById("Format");
const days=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
const months=["January","February","March","April","May","June","July","August","September","October","November","December"];
let toggle=false;
const ampm=document.getElementById("ampm");
function updateClock(){
const now=new Date();
let hours=now.getHours();
ampm.textContent=hours>=12?"PM":"AM";
if(toggle){
hours=hours%12 || 12;
}
hour.textContent=(hours).toString().padStart(2,"0");
min.textContent=now.getMinutes().toString().padStart(2,"0");
sec.textContent=now.getSeconds().toString().padStart(2,"0");
date.textContent=`Date: ${now.getDate().toString().padStart(2,"0")+"/"+(now.getMonth()+1).toString().padStart(2,"0")+"/"+now.getFullYear()}`;
month.textContent=`Month: ${months[now.getMonth()]}`;
day.textContent=`Day: ${days[now.getDay()]}`;
}
updateClock();
setInterval(updateClock,1000);
format.addEventListener("click",()=>{
toggle=!toggle;
format.innerText = toggle ? "24HR Format" : "12HR Format";
updateClock();
});