解析CIM_DateTime到.NET的DateTime [英] Parse CIM_DateTime to .Net DateTime
问题描述
我的应用程序正在接收来自WMI的一些最新信息。这与以下格式字符串的形式:
My application is receiving some date information from WMI. This in the form of strings with the following format:
yyyymmddHHMMSS.mmmmmmsUUU
有关此格式的详细信息,请参阅的此处。我感兴趣的时期之前分析的一切。我有以下代码:
For more details on this format, see here. I'm interested in parsing 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);
这总是失败的调用ParseExact(),有一个例外,说明字符串未被识别为有效的DateTime。我在做什么错在这里?
This always fails on the call to ParseExact(), with an exception stating that "String was not recognized as a valid DateTime." What am I doing wrong here?
推荐答案
这几乎是正确的。你想如下格式的字符串:
That's almost correct. You want the following format string:
yyyyMMddHHmmss
即两位数秒由小写的SS表示。
i.e. Two-digit seconds is represented by lower-case "ss".
这篇关于解析CIM_DateTime到.NET的DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!