字符串未被识别为有效的DateTime

时间:2021-05-10 10:33:47

I am getting this error: String was not recognized as a valid DateTime.

我收到此错误:字符串未被识别为有效的DateTime。

DateTime date = DateTime.ParseExact("4/29/2013", "MM/dd/yyyy", null);

1 个解决方案

#1


2  

Use one M instead of MM to match the format for months values that are one or two numbers.

使用一个M而不是MM来匹配一个或两个数字的月份值的格式。

The same goes for d for days.

d持续数天。

DateTime date = DateTime.ParseExact("4/29/2013", "M/dd/yyyy", null);

DateTime aDate = DateTime.ParseExact("4/2/2013", "M/d/yyyy", null);

#1


2  

Use one M instead of MM to match the format for months values that are one or two numbers.

使用一个M而不是MM来匹配一个或两个数字的月份值的格式。

The same goes for d for days.

d持续数天。

DateTime date = DateTime.ParseExact("4/29/2013", "M/dd/yyyy", null);

DateTime aDate = DateTime.ParseExact("4/2/2013", "M/d/yyyy", null);