- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleHTML
More file actions
Latest commit
29 lines (23 loc) · 524 Bytes
/
Copy pathSimpleHTML
File metadata and controls
29 lines (23 loc) · 524 Bytes
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
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Dates</h1>
<p>Add zeros and colons to display the time:</p>
<p id="demo"></p>
<script>
function addZero(x,n) {
while (x.toString().length < n) {
x = "0" + x;
}
return x;
}
const d = new Date();
let h = addZero(d.getHours(), 2);
let m = addZero(d.getMinutes(), 2);
let s = addZero(d.getSeconds(), 2);
let ms = addZero(d.getMilliseconds(), 3);
let time = h + ":" + m + ":" + s + ":" + ms;
document.getElementById("demo").innerHTML = time;
</script>
</body>
</html>