. Net time format conversion with Time Zone

Source: Internet
Author: User

. Net time format conversion with Time Zone

When obtaining information from WMI, it is found that the retrieved time format is quite special (for example, 20120321112421.535286 + 540) and datetime is directly implemented. tryparse conversion is still not normal conversion, after investigation, we know that this is the DMTF format of the time format.

string s = "20120321112421.535286+540";Console.WriteLine( ManagementDateTimeConverter.ToDateTime(s));

 

Output: 10:24:21. (My computer sets the China time zone. Therefore, the obtained time is automatically converted to the current time zone)

 

In addition, sometimes the returned time format is quite special when obtaining data from a third party (for example, Tue Mar 27 14:17:00 + 0900 2012 ), this also requires some custom skills for Normal conversion.

    string s = "Tue Mar 27 14:17:00 +0900 2012";    DateTime.TryParseExact(s, "ddd MMM dd HH:mm:ss zzz yyyy", System.Globalization.CultureInfo.CreateSpecificCulture("en-US"),        System.Globalization.DateTimeStyles.None, out dt);    Console.WriteLine(dt);

 

 

Output: 13:17:00

 

References:

DMTF time conversion: http://msdn.microsoft.com/zh-cn/library/system.management.managementdatetimeconverter.aspx

Custom time format: http://msdn.microsoft.com/zh-cn/library/8kb3ddd4.aspx

 

 

 

 

 

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.