c# - 如何使用 DateTime.Parse() 创建 DateTime 对象

标签 c# parsing datetime

如果我有一个格式为 yyyyMMddHHmmssfff 的字符串,例如 20110815174346225。我将如何从该字符串创建 DateTime 对象。 我尝试了以下

DateTime TimeStamp = DateTime.Parse(Data[1], "yyyyMMddHHmmssfff");

但是我得到了这些错误:

Error   1   The best overloaded method match for 'System.DateTime.Parse(string, System.IFormatProvider)' has some invalid arguments C:\Documents and Settings\rkelly1\Desktop\sd\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 67  29  WindowsFormsApplication1


Error   2   Argument 2: cannot convert from 'string' to 'System.IFormatProvider'    C:\Documents and Settings\rkelly1\Desktop\sd\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 67  53  WindowsFormsApplication1

最佳答案

var sDate = "20110815174346225";
var oDate = DateTime.ParseExact(sDate, "yyyyMMddHHmmssfff", CultureInfo.CurrentCulture);

关于c# - 如何使用 DateTime.Parse() 创建 DateTime 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7068843/

相关文章:

c# - 在 Ubuntu 上安装适用于 .NET 的 newtonsoft-json

c# - 如何阻止 EF 逆向工程师将表名称的复数更改为单数?

来自 WEBVTT 的 RDF/JSON 的 Javascript 解析器

perl - Marpa 可以用来加速 Perl 解释器的解析吗?

ruby-on-rails - Time.now.beginning_of_week 给出两个不同的值

c# - 从 C# 将 Bool 数组传递给 C++ 代码

c# - IPAddress.ToString 中的地址后面的百分号是什么?

c - 带管道 C 的 sscanf

python - 在Python中获取系统的时区信息?

c# - 如何在 C# 中显示测试性能数字的准确时间