views:

99

answers:

2

Hi,

I want to define the begin of a day in another timezone with .NET/C#.

Example: My current timezone = GMT+1 so DateTime.Today returns 19/11/2009 23:00 UTC

but actually I want to get the DateTime.Today for timezone GMT+2 which would be 19/11/2009 22:00 UTC.

How do I do this without juggling with offsets & daylightsaving calculations?

+1  A: 

Try:

var zone = TimeZoneInfo.GetSystemTimeZones().First(tz => tz.StandardName == DesiredTimeZoneName);
Debug.WriteLine(new DateTimeOffset(DateTime.UtcNow.Date.Ticks, zone.BaseUtcOffset).ToUniversalTime());

AFAIK, there's no other way to do this.

Inferis
+2  A: 

You can use TimeZoneInfo.ConvertTime. This is new in .NET 3.5.

bja