0

I have a scenario in which I have to show ticking time to the user of a post. The post will come with is original DateTime string from server then the values will be calculated on client to find the difference of the time elapsed. The issue is that client time can't be relied upon. So the decision is that to retrieve the server current time and find the difference between the client and server and add that difference to the client date and then add the difference to the client time before calcuating the time elapsed.. however I don't know how to find the difference in javascript and add it client date variable.. Can someone talk on this scenario and codify it.. I am not sure whether I am doing right or is there alternative to it?

spiral
  • 101
  • 3
  • 11
  • duplicate http://stackoverflow.com/q/6108819/1211980 – SachinGutte Mar 30 '13 at 14:45
  • I know how to do this .. What I say is that you can't actually trust the time of the client.. client can change his datetime any instant.. that is actually the issue how to cure this.. I mean.. – spiral Mar 30 '13 at 14:49
  • `So the decision is that to retrieve the server current time....` you already know the solution. Server will give you the time when the page is requested. Get it in javascript var and operate on it. – SachinGutte Mar 30 '13 at 14:52
  • Form a habit to use UTC time in distributed applications (like web apps) all the time and such questions won't arise. – Yuriy Rozhovetskiy Mar 30 '13 at 14:53
  • @phobos So how to find the difference and synchronize the clocks??? javascipt is needed.. – spiral Mar 30 '13 at 14:58
  • @YuriyRozhovetskiy how can UTC solve this?? this is about difference in the server and client I don't see any UTC application here... do you? – spiral Mar 30 '13 at 15:00
  • Why just don't return from server count of seconds since some event occured or till some event – Yuriy Rozhovetskiy Mar 30 '13 at 15:08
  • minute tick is the event which triggers the function.. I am doing currently this in webservice on server and calling it through ajax.. but that is something should to be handled on the client and can free the server from extra work.. – spiral Mar 30 '13 at 15:12
  • Ever tried to [search for the topic](http://www.google.de/search?q=stackoverflow+javascript+synchronize+server+time)? – Bergi Mar 30 '13 at 15:52

1 Answers1

0

So I come up with the solution now.. as I mentioned to use the variable to store the server current time and update that variable after each specific interval in setinterval. This variable is going to work as our client side clock and compare the post time with it.. the issue with client clock is that it can't be trusted..

spiral
  • 101
  • 3
  • 11