.NET/JavaScript ignores daylight saving (DST) when parsing ISO8601
I have been testing date/time parsing using .NET and JavaScript. This questing is linked to this one that I asked previously:
Parsing ISO8601 date/time with DateTime struct
Please note that the examples here are .NET. To get an example of this issue in JavaScript too, see the link above.
It appears that when parsing an ISO8601 format date/time, it ignores DST (daylight saving):
Example:
Console.WriteLine("Inspecting DateTime.Now");
DateTime now = DateTime.Now;
Console.WriteLine(now.ToLocalTime());
Console.WriteLine(now.ToUniversalTime());
Console.WriteLine("Inspecting ISO8601 Parsing");
DateTime dt = DateTime.Parse("1987-01-05T08:45:30.500+0100");
Console.WriteLine(dt.ToLocalTime());
Console.WriteLine(dt.ToUniversalTime());
Results:
// Inspecting DateTime.Now
// 27/08/2013 13:44:33
// 27/08/2013 12:44:33
// Inspecting ISO8601 Parsing
// 05/01/1987 07:45:30
// 05/01/1987 07:45:30
When I display local/universal time for DateTime.Now, this is correct. Britain is currently in DST (Daylight Saving Time, UTC+01:00).
When I display local/universal time for the ISO8601 string, this is incorrect, both are displaying UTC time. Local time should be "05/01/1987 08:45:30"
This issue occurs with JavaScript too.
If I change my time zone to something else (ie UTC+04:00), then I get the expected (correct) results, but with my current settings it seems to ignore DST (Daylight Saving Time).
Note: UK time zone IS UTC+00:00, but DST puts us in UTC+01:00...it's the latter that seems to be being ignored when parsing the date/time.
Any ideas why, or how to fix this?
链接地址: http://www.djcxy.com/p/29378.html