【发布时间】:2013-08-22 17:23:58
【问题描述】:
我有日期/时间格式,例如: “1-Mar-13 92230” 根据this document和this link,格式如下: “d-MMM-yy Hmmss”,因为:
Day is single digit, 1-30
Month is 3 letter abbreviation, Jan/Mar etc.
Year is 2 digits, eg 12/13
Hour is single digit for 24 hour clock, eg 9, 13 etc. (no 09)
Minute is standard (eg 01, 52)
Second is standard (eg 30, 02)
我试图在我的程序中运行以下代码,但我不断收到“字符串未被识别为有效日期时间”的错误。
string input = "1-Mar-13 92330";
var date = DateTime.ParseExact(input, "d-MMM-yy Hmmss",
System.Globalization.CultureInfo.CurrentCulture);
请帮忙,我对 DateTime 转换不太熟悉,但我看不出我在哪里出错了。谢谢!
更新:这是因为没有冒号就无法解析时间吗? (例如 1-Mar-13 9:22:30 被解析,但我有一个外部数据源无法从 Hmmss 重写为 H:mm:ss)
【问题讨论】: