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

前端 未结 8 660

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

    try this:

    string strTime = "04/30/2013 23:00";
    DateTime dtTime;
    if(DateTime.TryParseExact(strTime, "MM/dd/yyyy HH:mm",  
       System.Globalization.CultureInfo.InvariantCulture, 
       System.Globalization.DateTimeStyles.None, out dtTime))
     {
        Console.WriteLine(dtTime);
     }
    

提交回复
热议问题