What format is this time value in?

2019-01-14 23:50发布

问题:

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:

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.



回答2:

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.



回答3:

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].



回答4:

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)



回答5:

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

The format string is "yyyyMMddHHmmss.ffffffzzz"