timesync
Version:
Time synchronization between peers
33 lines (29 loc) • 909 B
HTML
<html>
<head>
<meta charset="UTF-8">
<!-- include es5-shim and es5-shim when support for older browsers is needed -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.0.5/es5-shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.23.0/es6-shim.min.js"></script>
<script src="/timesync/timesync.js"></script>
<script>
// create a timesync client
var ts = timesync.create({
server: '/timesync',
interval: 10000
});
// get notified on changes in the offset
ts.on('change', function (offset) {
console.log('changed offset: ' + offset + ' ms');
});
// get synchronized time
setInterval(function () {
var now = new Date(ts.now());
console.log('now: ' + now.toISOString() + ' ms');
}, 1000);
</script>
</head>
<body>
(see outputs in the developer console)
</body>
</html>