-
Notifications
You must be signed in to change notification settings - Fork 0
/
time.js
25 lines (18 loc) · 997 Bytes
/
time.js
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
function updateTime(){
const months = ["January", "February", "March", "April", "May", "June", "July", "August", "October", "September", "November", "December"];
const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
const date = new Date();
const day = date.getDate();
const weekDay = days[date.getDay()];
const month = months[date.getMonth()];
// time section (make sure to have the 0 before the 1 digit minutes and seconds)
let minutes = "" + date.getMinutes();
if (("" + date.getMinutes()).length == 1)
minutes = "0" + date.getMinutes();
let seconds = "" + date.getSeconds();
if (("" + date.getSeconds()).length == 1)
seconds = "0" + date.getSeconds();
const time = date.getHours() + ":"+ minutes + ":" + seconds;
document.getElementById("currenttime").innerHTML = weekDay + ", " + month + " " + day + ", " + date.getFullYear() + "\n" + time;
}
setInterval(updateTime, 1000);