I have a webservices that collects realtime market data and displays it in a web frontend.
My frontend (jQuery) needs to display a clock, somewhat synchronized with the server clock (+- a few seconds is fine).
I was thinking of delivering a UTC timestamp alongside the rest of the data the server provides when the client loads.
Then, I would start a timer and every 1 seconds increment the displayed clock.
Is this a good approach or is it better to use a time server?
Thanks!
You need to account for network latency. Data from your server won't reach you instantly. I suggest doing it using Cristian algorithm:
Read more about clock synchronization algorithms on wikipedia
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With