[英]String to datetime: not recognized as a valid DateTime
Ok so after some research I haven't found any way to solve my problem . 好吧,经过一番研究,我还没有找到解决我问题的方法。
This is my String to Date conversion code: 这是我的String to Date转换代码:
DateTime startDate = new DateTime();
startDate = DateTime.ParseExact(this.items[5], "dd/MM/yyyy HH:mm:ss",
CultureInfo.InvariantCulture);
And this is the string I want to convert: 这是我要转换的字符串:
"22/2/2013 09:57:32"
But when I compile I have this error: 但是当我编译的时候我有这个错误:
String was not recognized as a valid DateTime.
字符串未被识别为有效的DateTime。
What should I do? 我该怎么办?
Your pattern should be "dd/M/yyyy HH:mm:ss"
你的模式应该是
"dd/M/yyyy HH:mm:ss"
MM
requires leading 0, which is not provided in your input string. MM
需要前导0,这在输入字符串中没有提供。
You need a single M
instead of MM
for month . 您一个月需要一个
M
而不是MM
。 So format should be: "dd/M/yyyy HH:mm:ss"
所以格式应该是:
"dd/M/yyyy HH:mm:ss"
Just one 'M' required for Month.
月份只需要
一个“M”。 EX:
"dd/M/yyyy HH:mm:ss"
例如: “ dd / M / yyyy HH:mm:ss”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.