. 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