C# 为什么DateTime.ParseExact格式;dd-MMM-yyyy“;如果发送单个数字,则引发异常
我正在尝试使用以下格式解析发送的日期:C# 为什么DateTime.ParseExact格式;dd-MMM-yyyy“;如果发送单个数字,则引发异常,c#,datetime,C#,Datetime,我正在尝试使用以下格式解析发送的日期:19 maj 2011 这可以用DateTime.ParseExact(“2011年6月19日”、“2011年5月19日”、“新文化信息”(“sv SE”))轻松解析 但是,我也可以获取格式为2011年4月1日的日期 这将抛出带有消息的System.FormatException “字符串“1 maj 2011”未被识别为有效的日期时间。” 但是,如果我使用d MMM yyyy作为格式,则19 maj 2011和1 maj 2011都可以使用 d
19 maj 2011
这可以用DateTime.ParseExact(“2011年6月19日”、“2011年5月19日”、“新文化信息”(“sv SE”))轻松解析代码>
但是,我也可以获取格式为2011年4月1日的日期
这将抛出带有消息的System.FormatException
“字符串“1 maj 2011”未被识别为有效的日期时间。”
但是,如果我使用d MMM yyyy
作为格式,则19 maj 2011
和1 maj 2011
都可以使用
d Represents the day of the month as a number from 1 through 31. A single-digit day is formatted without a leading zero
dd Represents the day of the month as a number from 01 through 31. A single-digit day is formatted with a leading zero
ddd Represents the abbreviated name of the day of the week (Mon, Tues, Wed etc)
dddd Represents the full name of the day of the week (Monday, Tuesday etc)
来源:将日期解析为“01 maj 2011”
,因为是你告诉它的,警官。@AndréSanson我不控制其他系统,然后使用d MMM yyyy
另一个有用的链接: