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

前端 未结 7 2229
遇见更好的自我
遇见更好的自我 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:12

    If you give the user the opportunity to change the date/time format, then you'll have to create a corresponding format string to use for parsing. If you know the possible date formats (i.e. the user has to select from a list), then this is much easier because you can create those format strings at compile time.

    If you let the user do free-format design of the date/time format, then you'll have to create the corresponding DateTime format strings at runtime.

提交回复
热议问题