Clock-accurate timeout for Node.js and browser
Clock-accurate timeout for Node.js and browser. Basically it is identical to setTimeout, but it triggers callback function precisely on the next second.
Tick at (hh:mm:ss:ms)
(compare to your computer's clock..)
var Ractive = require('ractive')
var tick = require('clocktick')
var ractive = new Ractive({
el: '#ractive-container',
template: '{{timestamp}}'
})
tick(updateTimestamp)
function updateTimestamp () {
var now = new Date()
var hours = ('0' + now.getHours()).slice(-2)
var minutes = ('0' + now.getMinutes()).slice(-2)
var seconds = ('0' + now.getSeconds()).slice(-2)
var milliseconds = ('00' + now.getMilliseconds()).slice(-3)
var timestamp = hours + ':' + minutes + ':' + seconds + ':' + milliseconds
ractive.set('timestamp', timestamp)
tick(updateTimestamp)
}
Read documentation from Github