I have a server running in New York that saves a DateTime into the database in local time.
I then have a client application running in GMT timezone that needs to save down a DateTime in the same local New York time
Can I do using:
TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"))
The TimeZoneInfo class should give you what you need.
var date = (DateTime)reader; // Retrieve data from database however you normally get it var est = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); var utcTime = TimeZoneInfo.ConvertTimeToUtc(date, est); var localTime = utcTime.ToLocalTime();
Edit: You modified your question to indicate you have looked at TimeZoneInfo, so this doesn't add much anymore. However to resolve the ambiguous time issue mentioned by Jon, take a look at the
GetAmbiguousTimeOffsets() methods to be able to detect values that can't be definitively converted.