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

前端 未结 8 668

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:16

    Your date time string doesn't contains any seconds. You need to reflect that in your format (remove the :ss).
    Also, you need to specify H instead of h if you are using 24 hour times:

    DateTime.ParseExact("04/30/2013 23:00", "MM/dd/yyyy HH:mm", CultureInfo.InvariantCulture)
    

    See here for more information:

    Custom Date and Time Format Strings

提交回复
热议问题