简体   繁体   English

解析正确时,无法将字符串识别为有效的DateTime

[英]String was not recognized as a valid DateTime when parse exact

I'm getting this error: 我收到此错误:

String was not recognized as a valid DateTime. 无法将字符串识别为有效的DateTime。

When trying to parse this date: 尝试解析此日期时:

DateTime.ParseExact("2015-08-05", "YYYY-MM-dd", CultureInfo.InvariantCulture)

What's wrong with the date format and how do I fix this? 日期格式有什么问题,如何解决?

The "YYYY" portion needs to be lower-case: “ YYYY”部分必须为小写:

DateTime.ParseExact("2015-08-05", "yyyy-MM-dd", CultureInfo.InvariantCulture)

Reference: The "yyyy" Custom Format Specifier 参考: “ yyyy”自定义格式说明符

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM