Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Client Time

Tags:

asp.net

I would like to be able to display time based on the user's current time zone. I will be storing times in UTC format in my database, but wish to normalize these to the client's time zone. So far the option that seems most viable is to capture the clients time and then deteremine the difference between that and current UTC and use that delta to normalize times when rendering. I would like to know if there are any more straight forward options available to detect and normalize a UTC time to that of the requesting client's machine.

like image 325
JPrescottSanders Avatar asked Mar 23 '09 01:03

JPrescottSanders


2 Answers

I would use the javascript dateObject.getTimezoneOffset(). Even if their time isn't set accurately, hopefully they've set their timezone:

http://www.w3schools.com/jsref/jsref_getTimezoneOffset.asp

You can use this value to calculate an offset between the server's time and the client's time. (as Jason helpfully pointed out in a comment below)

like image 112
Keltex Avatar answered Sep 18 '22 22:09

Keltex


In addition to, or instead of using getTimezoneOffset, you should consider permitting the user to specify preferred timezone in their profile. For instance, a user may be visiting in one timezone, yet may prefer to see time displayed in his home timezone.

Also, if this were as simple as calling a JavaScript function, then sites would never have to ask for your timezone.

like image 40
John Saunders Avatar answered Sep 20 '22 22:09

John Saunders