Skip to content

Commit

Permalink
Create clock.js
Browse files Browse the repository at this point in the history
  • Loading branch information
krishiv8190 authored Oct 5, 2021
1 parent fc823f6 commit fa789d0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Program's_Contributed_By_Contributors/JavaScript_Programs/clock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function currentTime() {
var date = new Date();
var hour = date.getHours();
var min = date.getMinutes();
var sec = date.getSeconds();
hour = updateTime(hour);
min = updateTime(min);
sec = updateTime(sec);

document.getElementById("clock").innerText = hour + " : " + min + " : " + sec;
var t = setTimeout(function(){ currentTime() }, 1000);
}

function updateTime(k) {
if (k < 10) {
return "0" + k;
}
else {
return k;
}
}

currentTime();

0 comments on commit fa789d0

Please sign in to comment.