D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
dslanger
Full window
Github gist
JS Bin // source https://jsbin.com/lolilod
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>JS Bin</title> </head> <body> <script id="jsbin-javascript"> // every second, log time 'use strict'; setInterval(logClockTime, 1000); function logClockTime() { // var time = getClockTime(); // console.clear(); console.log(time); } function getClockTime() { // get current time var date = new Date(); var time = ''; // serialize time var time = { hours: date.getHours(), minutes: date.getMinutes(), seconds: date.getSeconds(), ampm: 'AM' }; // convert to civillian time if (time.hours == 12) { time.ampm = 'PM'; } else if (time.hours > 12) { time.ampm = 'PM'; time.hours -= 12; } // prepend a 0 on the hours for double digits if (time.minutes < 10) { time.minutes = '0' + time.minutes; } // prepend a 0 on the minutes for double digits if (time.hours < 10) { time.hours = '0' + time.hours; } // prepend a 0 on the seconds for double digits if (time.seconds < 10) { time.seconds = '0' + time.seconds; } // format the clock time as a string 'hh:mm:ss tt' return time.hours + ':' + time.minutes + ':' + time.seconds + ' ' + time.ampm; } </script> <script id="jsbin-source-javascript" type="text/javascript">// every second, log time setInterval(logClockTime, 1000); function logClockTime() { // var time = getClockTime(); // console.clear(); console.log(time); } function getClockTime() { // get current time var date = new Date(); var time = ''; // serialize time var time = { hours: date.getHours(), minutes: date.getMinutes(), seconds: date.getSeconds(), ampm: 'AM' }; // convert to civillian time if (time.hours == 12) { time.ampm = 'PM'; } else if (time.hours > 12) { time.ampm = 'PM'; time.hours -= 12; } // prepend a 0 on the hours for double digits if (time.minutes < 10) { time.minutes = '0' + time.minutes; } // prepend a 0 on the minutes for double digits if (time.hours < 10) { time.hours = '0' + time.hours; } // prepend a 0 on the seconds for double digits if (time.seconds < 10) { time.seconds = '0' + time.seconds; } // format the clock time as a string 'hh:mm:ss tt' return time.hours + ':' + time.minutes + ':' + time.seconds + ' ' + time.ampm; }</script></body> </html>