Skip to content

Commit

Permalink
Create digitalclock.js
Browse files Browse the repository at this point in the history
  • Loading branch information
dhairyagothi authored Feb 22, 2024
1 parent 57639a1 commit ba50db2
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions digital_clock/digitalclock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
setInterval(showtime,0);
setInterval(setdate,0);

function showtime(){
let time = new Date() ;
let hour = time.getHours();
let minutes = time.getMinutes();
let seconds = time.getSeconds();
am_pm = "AM";
if(hour>=12){
hour-=12;
am_pm="PM";
}
else if (hour==0){
hr=12;
am_pm="AM";
}
if(hour<10){
hour = "0"+hour;
}
if(minutes<10){
minutes = "0"+minutes;
}if(seconds<10){
seconds = "0"+seconds;
}
let currenttime = hour+":"+minutes+":"+seconds+" "+am_pm;

document.getElementById("clock").innerHTML=currenttime;
}
function setdate(){
let today = new Date();
let date = today.getDate()
let month = today.getMonth()+1;
let year = today.getFullYear()
let day = today.getDay();


let todaydate= date+"/"+ month +"/"+year+","+day;

document.getElementById("date").innerHTML=todaydate;
}

setdate();
showtime();

0 comments on commit ba50db2

Please sign in to comment.