views:

269

answers:

5

I have a WMI query that specifies time in this format '20090219000000.000000+480'

Can someone tell me what format this is, and does .NET have any built-in functionality to work with it?

EDIT

This time value is from a sample query that I found. I don't know what time value was used to generate it. I just need to be able to convert a time value to this format.

EDIT 2

I found out this time is in CIM_DATETIME format.

+1  A: 

Take a look at this link. Just by looking I'd say it's in a format of yyyyMMddhhmmss.[a whole bunch of 'f' characters].

Jason Down
+1  A: 

It would help if you told us was date it represented. It 2009 at the start suggests it may be YYYYMMDDHHMMSS.FFFFFF+TZ

(F= fraction of seconds, and TZ being difference from UTC in minute, so here, 6 hours)

James Curran
Need to be careful with the case of the characters. MM is month, where mm is minutes.
Jason Down
That wasn't intended as a format string, merely a (human readable) description.
James Curran
+10  A: 

This looks like a standard date time string without any separators:

'20090219000000.000000+480'

'yyyyMMddhhmmss.ffffff+480'

yyyy - The year in four digits.
MM - The numeric month. Single-digit months have a leading zero.
dd - The day of the month. Single-digit days have a leading zero.
hh - The hour in a 12-hour clock. Single-digit hours have a leading zero. (This could also be HH, which is the hour in a 24-hour clock with single-digit hours having a leading zero.)
mm - The minute. Single-digit minutes have a leading zero.
ffffff - The fraction of a second in six-digit precision.

The "+480" is most likely a timezone indicator, although not a standard one. Normally time zones are represented as hours (or hours and minutes) from UTC. This appears to probably only be minutes. As such, there is no standard format specifier.

The DateTime class in .NET is what you would use to work with this value. However, you would probably want to take the "+480" portion off before parsing the remaining string in to an actual DateTime variable. You can then adjust it to the correct timezone or perform the timezone conversion (from minutes to hours/minutes) ahead of time and change the "+480" to the correct timezone representation and then pass the whole thing to DateTime.Parse.

Scott Dorman
A: 

You can parse this with DateTime.ParseExact-Methode (String, String, IFormatProvider, DateTimeStyles)

The format string is "yyyyMMddHHmmss.ffffffzzz"

PVitt
+4  A: 

As others have suggested the string is an example of DATETIME MOF data type. It is a fixed-length string and you can find details about its structure here. .Net uses System.Management namespace to access WMI and one of its classes is ManagementDateTimeConverter class which facilitates working with WMI datetime values.

Uros Calakovic
System.Management.ManagementDateTimeConverter.ToDateTime((string)result.GetPropertyValue("TimeWritten"));Could have saved me an hour of writing it myself =P
Merlyn Morgan-Graham
I've been search for an hour for a way to convert this. Thanks Merlyn
Khalid Rahaman