开发者

Syncing JS+PHP time

Since the Date constructor is based on your PC's timezone a开发者_开发知识库nd server-side is obviously dependent on the server's time settings...

What procedures can I do to ensure that the timestamps I generate are consistent on both ends?

I have a jQuery datepicker setup and I do a lot of work, I also have my own datepicker that's generated from server-side code which looks up db availability for bookings.

I'm saving arrival/departure times on the server-side and the days are off by one because the JS is local timezone ( mine is Eastern ) .

Is my only option doing something like making the JS call PHP to grab a timestamp?


You could have your client query the server once at startup to get the server's time, then calculate the difference between the time on the client and the time reported by the server. Cache this value, and use it for future requests. You may still be off by a few seconds (owing to the request latency), but you'll be pretty close.


You need to use one time reference (typically UTC/GMT) see this.

https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-6016329.html


Your server and client application should get the time from a remote server (timeserver)


You only need sync the server time from a time server. Evry time your application is working in the client side read this sync-ed time from a reference table.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜