-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #623 from krishiv8190/patch-1
Create clock.js
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
Program's_Contributed_By_Contributors/JavaScript_Programs/clock.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |