fhsav / clock.js

The FHS Clock built with Node.
https://fhsclock-js.herokuapp.com
Mozilla Public License 2.0
5 stars 2 forks source link

Provide server time during page load #16

Closed gluxon closed 9 years ago

gluxon commented 9 years ago

Just tested with the following code:

// Sync with server time by calculating offset
var serverTimeString = $('#date').text().trim() + ' ' + $('#time').text().trim();
var serverTimeX = moment(serverTimeString, 'dddd, MMMM D, YYYY h:mm:ss').format("X");
var difference = serverTimeX - moment().format('X');
console.log(difference);

This method is too unreliable due to page load time. (difference may be 0-2 seconds off on a machine providing both the server and client.) If there is a browser API to get load time in the future, this may be viable.