views:

1385

answers:

7

I want to implement timezone in my web application. I researched and saw most web app use a GMT dropdown, here is the link to that dropdown http://www.attackwork.com/BlogEntry/6/Time-Zone-Dropdown-Select-List/Default.aspx

Then I saw this article suggesting UTC is the way to go when it comes to implement timezone. http://aspnet.4guysfromrolla.com/articles/081507-1.aspx Basically it's saying don't use DateTime.Now instead use DateTime.UtcNow

My questions are,

  1. Is there a dropdown of the timezones in UTC, like the first link I showed there is one on GMT?
  2. Should I really use UTC or GMT?
+1  A: 

GMT (Greenwich Mean Time) is the same as UTC (Universal Coordinated Time). This isn't an either/or choice - use it :)

Harper Shelby
GMT isn't actually the same. They have different origins. See the link I posted below.
David Morton
Interesting. I knew the naming origins were different, but I didn't know the specific distinction.
Harper Shelby
+1  A: 

This is one of the ways to do it if you are using sql server 2008. Let the back end provide you with relevant info.

Perpetualcoder
+3  A: 

.NET 3.5 provides the TimeZoneInfo class which should make it relatively simple for you to populate a dropdown with time zones. GMT came before UTC and UTC was officially instituted on January 1, 1972. See this link for more information. For today's purposes, the two are pretty much synonymous, though they have different historical origins. Use whichever looks and functions better for your purposes.

David Morton
A: 

Use Localization settings, functions and features anywhere possible.

Jas Panesar
A: 

If you aren't running against SQL Server 2008 or don't want to abstract timezone management to the database, you should store all times as UTC/GMT and apply the timezone difference based off the user's profile setting, so that users from all around the world can see timestamps on events in their local time.

JMs
+1  A: 

I'm not sure if this is what you intended to ask, but in your database you should always store timestamps in UTC/GMT (as noted by others they mean essentially the same thing). For each user of your web app, store the time zone preference.

Then whenever you display the timestamp for something to a user, convert the UTC time in the database to the user's timezone.

DSO
A: 

The distinction between UTC and GMT is probably too fine to bother with in your code. However, it's probably a good idea to always save and process times internally with zero timezone offset, and deal with it as a presentation concern.

It's also possible to use JavaScript to determine the user's probable timezone: examine the timezone offsets for some pair of Date objects reasonably close to the solstices (even January 1 and July 1 makes a suitable approximation) to obtain a coarse timezone identification. Feel free to use this information to determine a default timezone, but do allow it to be changed by the user: JavaScript doesn't provide sufficient detail to select the exact timezone with national and regional historical shifts, and it may not be enabled by the user anyway.

Jeffrey Hantin