[ Solved ] Mizzao:timesync

#1

Little example about mizzao:timesync.

let currentTime = new Date();

Tracker.autorun( () => {
    // This will run automatically every time the serverTime updates. ie. every 60 seconds
    TimeSync.serverTime(null, 60000);
    currentTime = new Date( Date.now() + TimeSync.serverOffset() );
});

setInterval( () => {
    // This calculates the approximate server time and updates the DOM every second
    currentTime = new Date( Date.now() + TimeSync.serverOffset() );
    document.getElementById('time').innerText = currentTime.toLocaleDateString();
}, 1000);
2 Likes