user1438082 user1438082 - 1 month ago 10
C# Question

Date Time Format of 20131205205012.000000-000

When i query using WMI the event log the time an event occurred is 20131205205012.000000-000 for example

how can i convert this to yymmdd hh:mm:ss or similar
Out of interest what format is this ?

C# Code

this.radGridViewEvents.Columns.Add("Time Written");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_NTLogEvent WHERE EventType = 1");
foreach (ManagementObject queryObj in searcher.Get())
{
this.radGridViewEvents.Rows.Add(queryObj["TimeWritten"]);
}

Answer

Its UTC format, similar to this but without the seperators/punctuation;

2013-12-05T18:13:27+00:00

I am unsure what the -000 represents, but I assume the rest are the second fractions. One way to parse it is to use DateTime.ParseExact. Assuming you trim off the -000, you can parse the rest like so;

var date = DateTime.ParseExact("20131205205012.000000", 
                                           "yyyyMMddHHmmss.ffffff",
                                           CultureInfo.InvariantCulture,
                                           DateTimeStyles.AssumeUniversal |
                                           DateTimeStyles.AdjustToUniversal);
Comments