From cf9cdaade95defa2e78b5bd78105a072f028eefc Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sun, 23 Feb 2014 14:52:33 -0800 Subject: Implement a working date/time display. --- index.html | 6 ++++-- tempo.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 tempo.js diff --git a/index.html b/index.html index b816e62..97c3c46 100644 --- a/index.html +++ b/index.html @@ -4,13 +4,15 @@ New Tab + +
-

124527

+

 

-

23 February 2014

+

 

diff --git a/tempo.js b/tempo.js new file mode 100644 index 0000000..db8c039 --- /dev/null +++ b/tempo.js @@ -0,0 +1,35 @@ +var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; + +function padTime(x) { + if(x < 10) { + return "0" + x; + } else { + return x; + } +} + +function updateTime() { + var date = new Date(); + + var h = date.getHours(); + var m = date.getMinutes(); + var s = date.getSeconds(); + + var dd = date.getDate(); + var dm = date.getMonth(); + var dy = date.getFullYear(); + + var str_t = padTime(h) + ":" + padTime(m) + ":" + padTime(s); + var str_d = dd + " " + months[dm] + " " + dy; + + document.getElementById("timeval").innerHTML = str_t; + document.getElementById("dateval").innerHTML = str_d; +} + +function startTempo() { + updateTime(); + + setInterval(updateTime, 1000); +} + +window.onload = startTempo; -- cgit v1.2.3-70-g09d2