DateTime.TryParse issue with dates of yyyy-dd-MM format

前端 未结 7 2222
遇见更好的自我
遇见更好的自我 2020-12-08 12:54

I have the following date in string format \"2011-29-01 12:00 am\" . Now I am trying to convert that to datetime format with the following code:

DateTime.Try         


        
7条回答
  •  天命终不由人
    2020-12-08 13:09

    From DateTime on msdn:

    Type: System.DateTime% When this method returns, contains the DateTime value equivalent to the date and time contained in s, if the conversion succeeded, or MinValue if the conversion failed. The conversion fails if the s parameter is null, is an empty string (""), or does not contain a valid string representation of a date and time. This parameter is passed uninitialized.

    Use parseexact with the format string "yyyy-dd-MM hh:mm tt" instead.

提交回复
热议问题