Is it Microsoft's bug about the. NET datetime Format String? Please give answers!

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.