Reliable Way To Convert DateTime Values from UTC to CST and Back

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Is there a reliable way in Dot Net 2.0 to convert Date Time values between UTC and CST when the local computer is set to other than CST?

It must work on operating systems for W2K and up.

I found some sample code on CodeProject.com

http://www.codeproject.com/KB/cs/timezoneconversions.aspx

It is the best that I have found so far, but it isn't completely reliable. For example it uses TzSpecificLocalTimeToSystemTime() to convert dates from a specific time zone to UTC, which requires Windows XP and higher. It also uses the time zone's "index" registry value which isn't present in Vista. In order to find the CST entry I have to resort to string compares on Vista which makes the code much more fragile.

It also seems to have issues determining the current time zone. If I set the zone to Arizona for example, it doesn't find the zone properly.

What we have is a SQL database located on a server in CST and a Access Database copy of that SQL database on the user's computer. The user can access the data through a web interface or the local desktop application. The dates in both cases need to match otherwise we get off by a day issues and things like that. When you store dates, they are stored with a time value set to midnight. If the date gets adjusted for time zone, it may display the date as the previous day instead of the date that was entered.

Thanks,
Bruce

.



Relevant Pages