如果我有一个格式为 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/