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

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

    This should work based on your example "2011-29-01 12:00 am"

    DateTime dt;
    DateTime.TryParseExact(dateTime, 
                           "yyyy-dd-MM hh:mm tt", 
                           CultureInfo.InvariantCulture, 
                           DateTimeStyles.None, 
                           out dt);
    
    0 讨论(0)
提交回复
热议问题