简体   繁体   English

DateTime.ParseExact引发FormatException

[英]DateTime.ParseExact raises FormatException

The code: 编码:

DateTime.ParseExact("2/2/2002", "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture)

is raising System.FormatException . 正在引发System.FormatException

I'll really appreciate if anybody could tell me what am I doing wrong. 如果有人能告诉我我在做什么错,我将不胜感激。

it should be d/M/yyyy 应该是d/M/yyyy

DateTime.ParseExact("2/2/2002", "d/M/yyyy", System.Globalization.CultureInfo.InvariantCulture)

the reason of exception is that it converts two places for dd but the string found is 2/ . 出现异常的原因是它将dd转换为两个位置,但是找到的字符串为2/

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

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