Synchronize local app times via internet

Asked

Viewed 208 times

0

Hello.

I have an application that I’m building in cakephp. The application keeps showing the date and time on the page, but it’s computer time. How do I get the time of some server or internet link?

  • The time of PHP(cake) comes from the server that is configuring with some Timezone or UTC, to pick the client’s time will need javascript, remember that this is not reliable.

  • 1

    What I’ve seen them do (I’ve never needed it exactly this way), and it’s good, is to load the server time, and increase it with JS, by the difference of the client clock. Just don’t trust the "interval", because it accumulates offset. That is, it sends the time, the JS picks the server time, and increments with the offset of the client clock. In the client the time may be different, but in theory, time advances at the same speed :). If you need a lot of precision, then you will need a more robust mechanism (calculate the time of an ajax, use websockets etc), but I think it’s too much if it’s just a watch.

  • @Bacco is what I want to do. Take the external time and not the pc time. If the pc has the wrong clock, cakephp will also show wrong.

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.