Given a date and time structured as:
"2011-10-21 14:44:19"
which is known to be Pacific Time (adjusted for Daylight Savings when appropriate), I need to parse the DateTime and convert it to UTC, irrespective of the current server time.
I have seen this very similar question that starts with the assumption that the original DateTime is in UTC:
How to format a datetime to GMT irrespective of regional settings?
I'm trying to apply that to my situation, but don't understand how to begin with a Pacific Time (PST or PDT as appropriate) string and arrive at a UTC DateTime. Specifically, that solution applies the flag DateTimeStyles.AssumeUniversal
, whereas I need to assume Pacific Time.
You are going to have to use TimeZoneInfo.ConvertTimeToUtc(DateTime, TimeZoneInfo) to make the conversion. The server's timezone doesn't matter. Use FindSystemTimeZoneById() to select the timezone you pass as the second argument. You'll want "Pacific Standard Time" for the id.
This function uses a timezone database that's stored in the registry and maintained by Windows. Timezone rules change over time, particularly daylight savings transitions, so keeping Windows Update active on that machine is important to allow Microsoft to update the database. Clearly knowing exactly where the string came from is important for this to work correctly at all.