What are the configuration rules for converting DateTime to UTC?

On the MSDN page for TimeZoneInfo.ConvertTimeToUtc()there is an information window:

If the current local time zone of the computer includes several configuration rules, this overload of the ConvertTimeToUtc method can return results that differ from the TimeZone.ToUniversalTime and DateTime.ToUniversalTime methods. TimeZone.ToUniversalTime always applies the current setting rule to the time zone conversion, regardless of whether the dateTime is within its date range. And when executed on the .NET Framework 3.5, DateTime.ToUniversalTime also applies the current configuration rule to the time zone conversion, regardless of whether the dateTime is within its date range.

I'm not sure I understand what this means. What are these adjustment rules and how will the results differ between ConvertTimeToUtc()and TimeZone.ToUniversalTime()?

+4
source share
1 answer

Here is an example. At the time of writing this message, my computer is installed in the US time zone in the Pacific, and today is March 2, 2015. This is currently Pacific Standard Time (or PST), which is 8 hours behind UTC.

DateTime dt = new DateTime(2006, 4, 1, 0, 0, 0);
TimeZoneInfo tzi = TimeZoneInfo.Local;
DateTime utc = TimeZoneInfo.ConvertTimeToUtc(dt, tzi);

, 1 2006 , UTC. ( PST). TimeZoneInfo, . - 1 2006 8:00 UTC.

:

DateTime dt = new DateTime(2006, 4, 1, 0, 0, 0);
TimeZone tz = TimeZone.CurrentTimeZone;
DateTime utc = tz.ToUniversalTime(dt);

, . 7:00 UTC.

- , United States . 2007 . DST , , , .

, TimeZoneInfo , TimeZone . , .

TimeZone, MSDN :

!
TimeZoneInfo TimeZone.

, TimeZone .NET CoreCLR.

" " MSDN TimeZoneInfo.AdjustmentRule, . - , , .

wikis StackOverflow , .

Pluralsight, , .

: DateTime.ToUniversalTime TimeZoneInfo.ConvertTimeToUtc?

+6

All Articles