views:

387

answers:

1

Is there a way to set a .NET application's TimeZone to a value other than the OS's TimeZone?

For instance, I am using my application on an OS with Central Standard Time set, and I would like the app to behave as if it were in Eastern Standard Time, without having to manually convert all DateTimes in my application using a method like TimeZoneInfo.ConvertTimeBySystemTimeZoneId().

+4  A: 

No, I don't believe there's any way of doing this. It's not like the time zone is set on a per thread basis like the culture. For instance, I believe that DateTime.ToLocalTime will always use the system time zone

However, I wouldn't use TimeZoneInfo.ConvertTimeBySystemTimeZoneId everywhere. I'd expose a property of type TimeZoneInfo which represented the appropriate time zone - or set up a helper class to convert where you need to.

Depending on your app, you may well find that if you choose the right points at which to convert the data (which isn't always a case of just keeping it in UTC everywhere apart from the UI layer) you don't have as many conversions to perform as you might expect.

Jon Skeet
We ended up abstracting the TimeZoneInfo.ConvertTimeBySystemTimeZoneId to one of our DateTime helper classes, so we didn't need to expose the "Eastern Standard Time" constant everywhere in our code
Matthew Cole