Datetime format Issue: String was not recognized as a valid DateTime

前端 未结 8 637

I want to format the input string into MM/dd/yyyy hh:mm:ss format in C#.
The input string is in format MM/dd/yyyy hh:mm:ss
For example :

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 09:03

    change the culture and try out like this might work for you

    string[] formats= { "MM/dd/yyyy HH:mm" }
    var dateTime = DateTime.ParseExact("04/30/2013 23:00", 
         formats, new CultureInfo("en-US"), DateTimeStyles.None);
    

    Check for details : DateTime.ParseExact Method (String, String[], IFormatProvider, DateTimeStyles)

提交回复
热议问题