Re: Finding the offset of a specific time zone
Eddie Lascu <[email protected]> Wed, 25 Mar 2009 13:23:33 -0400
| Newsgroups | gmane.comp.windows.devel.dotnet.advanced |
|---|---|
| Organization | IBI Group |
| Message-ID | <[email protected]> |
Thanks Peter. Please note that your solution only works on .NET 3.5. TimeZoneInfo is not available for previous versions. This is why I have all these issues. Our server environment only has .NET 3.0. For versions prior to 3.5, one needs a similar class. One such class (written in VB) can be found here: http://www.codeproject.com/KB/vb/TimeZoneInfo.aspx Regards, Eddie -----Original Message----- From: Discussion of advanced .NET topics. [mailto:[email protected]] On Behalf Of Peter Ritchie Sent: Wednesday, March 25, 2009 1:12 PM To: [email protected] Subject: Re: [ADVANCED-DOTNET] Finding the offset of a specific time zone Yes, you'll have to make an assumption about the timezone of the time stamp if it's not coming in as UTC (I deal with "field devices" and they send UTC times...). You can do what you want with something like: DateTime datetime = new DateTime(1968, 11, 5, 12, 0, 0); DateTime utcDateTime = TimeZoneInfo.ConvertTimeToUtc(datetime, TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time")); // TODO: persist utcDateTime somwhere. For future readers, convert back to local time to display in the application like this: DateTime localDateTime = utcDateTime.ToLocalTime(); =================================== View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives =================================== View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives