BUG: In the tostring ("U") method, when the kind attribute of datetime is local, it cannot be automatically converted to UTC time, resulting inThe string with "Z" at the end of the returned result is the local time, and the string with "Z" at the end is the UTC time..
It is normal when the datetime kind attribute is UTC.
Summary:
5.1.2 characters used by the flag
[Z] Coordinated Universal Time (UTC) identifier, Directly following a Data Element (with no interval), the Coordinated Universal Time is used to represent the time of the day.
Datetime
1 Datetime n = Datetime. now;
2 Console. writeline (N ); // 2010/3/15 14:07:41
3 Console. writeline (N. kind ); // Local
4 Console. writeline ();
5
6 String S = N. tostring ( " U " );
7 Console. writeline (s ); // 2010-03-15 14: 07: 41z
8 Datetime t = Datetime. parse (s );
9 Console. writeline (t ); // 2010/3/15 22:07:41
10 Console. writeline (T. kind ); // Local
11 Console. writeline ();
12
13 String SS = N. tostring ( " O " );
14 Console. writeline (SS ); // 2010-03-15t14: 07:41.8178047 + 08: 00
15 Datetime TT = Datetime. parse (SS );
16 Console. writeline (TT ); // 2010/3/15 14:07:41
17 Console. writeline (TT. kind ); // Local
After tostring ("U"), the string ending with "Z" is representedLocal time.
In parse, the string with "Z" at the end is consideredUTC time.
In the same class, the Time Representation of the same string in different methods is different!
Other formats can be normally round-trips (the "O" format can retain the kind attribute, without reducing the accuracy), only the "U" format is 8 hours different. Is this a Microsoft Bug? Please give answers!
More formats: http://hi.baidu.com/hongcing/blog/item/736bb6437b412f1972f05d70.html