views:

681

answers:

2

Hi,

I need to know how to convert a date time of GMT time zone format into other formats like Eastern,Pacific,Mountain and India.. time zone formats in c#,asp.net2.0 and dot net frame work 2.0.

Thanks in Advance

Rupa.

+1  A: 

Using .NET 2.0 you're mostly stuffed, unfortunately. You'll need to use P/Invoke to create an instance of the TimeZone class. From .NET 3.5 onwards it's a lot better - TimeZoneInfo allows you to fetch non-local zones. I seem to remember that the latter has better support for historical time zone information too, instead of just a pair of rules for when DST changes.

You can get information using GetTimeZoneInformation but that's relatively ugly. There may well be some way of using P/Invoke just to make the conversion for you... although it's still likely to be hairy.

How firm is the requirement to use .NET 2.0? You'd save yourself a lot of hassle using .NET 3.5...

Jon Skeet
A: 

Really, you want .NET 3.5 for this...

(I know you asked about .NET 2.0, but this answer may be heplful for somebody searching for this topic in the future)

TimeZoneInfo mountain = TimeZoneInfo.FindSystemTimeZoneById(
    "US Mountain Standard Time");
DateTime utc = DateTime.UtcNow;
DateTime local = TimeZoneInfo.ConvertTimeFromUtc(utc, mountain);

Before then... pain. You can maintain your own list of offsets, but then you have to worry about DST.

Marc Gravell