What is the best way to detect and store the time zone in which the web application client is located?

I have a few hours web application that stores all datetime values ​​in UTC in the database, when actions happen on the server, I can easily convert the time to UTC.

However, when a client enters a period of time or time, what is the best way to detect and save it?

I am currently doing the following:

  • Get value of Date.getTimezoneOffset () (javascript)
  • Send this to the server code via the ICallbackEventHandler on the page.
  • Save this value in the session
  • In any subsequent query, calculate the output / input date / time value using the client’s time zone.

Regardless of the actual implementation, this seems like an elegant solution. Does anyone have a better method?

+5
source share
2 answers

I did something very similar, but now I think I prefer using javascript to convert all times to local on the client side. The server will give all the time in UTC on the generated page, and javascript will convert it after the page loads.

This eliminates the confusion in the server-side code, as I always know what time it is (UTC). On the client side, I use jquery and the each () function to format all the time values ​​at the same time. I write every time as unix time in a hidden field so that it is easy to handle using jquery.

, , , a) javascript, ) JavaScript, .

+4

"header" HttpRequest "If-Modified-Since", . , , :

If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT

. , , , .

,

+2

All Articles