解析CIM_DateTime到.NET的DateTime [英] Parse CIM_DateTime to .Net DateTime

查看:207
本文介绍了解析CIM_DateTime到.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆