DateTime.ToLocalTime () stopped working on XP in August 2013

We have a VB.NET application installed on a client PC running XP, on which DateTime.ToLocalTime () seems to have stopped working.

The problem first appeared in August 2013.

The client is in Texas and their time zone is correct.

The documentation for DateTime.ToLocalTime () has the following interesting note:

On Windows XP systems, the ToLocalTime method only recognizes the current configuration rule when switching from UTC to local time. As a result of conversions to the periods preceding the current adjustment rule that have entered into force, they may not accurately reflect the difference between GMT and local time.

Therefore, it seems likely that a change in the time zone setting was introduced in the August Windows update, which caused this.

I found the following: http://support.microsoft.com/kb/2863058 , which indicates that the cumulative time zone update was applied in August 2013, but no US rules look to be involved in this change.

Does anyone else have experience with this problem and (of course) a solution?

Edit

To clarify a bit. The time in question is stored in UTC in the SQL database, and we convert to LocalTime for display. This is the display that is causing the problem.

Events that were recorded at 1500 local time are now displayed as recorded at 2100.

+4
2

?

Format DateTime.Now,

:

        Textbox1.text = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") 
        Textbox1.Text = Format(now, "yyyy-MM-dd hh:mm:ss")

, y = , M = , d = , h = , m = , s = .

, . ( )

+2

, . (, , !)

, UTC-6. , (1500, 2100), 6 , , - .

, .Kind, DateTime. :

DateTime dt1 = new DateTime(2013, 11, 22, 3, 0, 0, DateTimeKind.Utc);
Debug.WriteLine("{0:HH:mm} ({1})", dt1, dt1.Kind);  // 3:00 (Utc)

DateTime dt2 = dt1.ToLocalTime();
Debug.WriteLine("{0:HH:mm} ({1})", dt2, dt2.Kind);  // 21:00 (Local)

DateTime dt3 = dt2.ToLocalTime();
Debug.WriteLine("{0:HH:mm} ({1})", dt3, dt3.Kind);  // 21:00 (Local)

- "", :

DateTime dt1 = new DateTime(2013, 11, 22, 3, 0, 0, DateTimeKind.Utc);
Debug.WriteLine("{0:HH:mm} ({1})", dt1, dt1.Kind);  // 3:00 (Utc)

DateTime dt2 = dt1.ToLocalTime();
Debug.WriteLine("{0:HH:mm} ({1})", dt2, dt2.Kind);  // 21:00 (Local)

// somehow, the kind is getting set back to unspecified in your code
dt2 = DateTime.SpecifyKind(dt2, DateTimeKind.Unspecified);

DateTime dt3 = dt2.ToLocalTime();
Debug.WriteLine("{0:HH:mm} ({1})", dt3, dt3.Kind);  // 15:00 (Local)

, DateTime.SpecifyKind. - , UTC.

, DateTime DateTime, . . , Local ?

, , . , .

, Windows Time Zone 2013 , . DST 2007 . 1 , 6.

0

All Articles