CIM_DateTime Parameter for .Net DateTime

My application receives date information from WMI. This is in the form of strings with the following format:

yyyymmddHHMMSS.mmmmmmsUUU 

Read more about this format here . I am interested in disassembling everything before the period. I have the following code:

  string testDate = "20010701212212"; // July, 01, 2001 21:22:12, in the format specified above string format = "yyyyMMddHHmmSS"; CultureInfo culture = CultureInfo.InvariantCulture; DateTime newDate = DateTime.ParseExact(date, format, culture); 

This always happens when calling ParseExact (), which states that "String was not recognized as a valid DateTime." What am I doing wrong here?

+5
c # datetime datetime-format
source share
2 answers

This is almost correct. You want the following format string:

 yyyyMMddHHmmss 

i.e. Double-digit seconds are represented by lowercase "ss".

+3
source share

Use ManagementDateTimeConverter .ToDateTime ()

The credit goes to Uros Kalakovich from this question.

+9
source share

All Articles