Convert string to Time

前端 未结 4 615
忘了有多久
忘了有多久 2021-02-01 13:23

I have a time that is 16:23:01. I tried using DateTime.ParseExact, but it\'s not working.

Here is my code:

string Time = \"16:23:01\"; 
Date         


        
4条回答
  •  无人共我
    2021-02-01 14:01

    This gives you the needed results:

    string time = "16:23:01";
    var result = Convert.ToDateTime(time);
    string test = result.ToString("hh:mm:ss tt", CultureInfo.CurrentCulture);
    //This gives you "04:23:01 PM"  string
    

    You could also use CultureInfo.CreateSpecificCulture("en-US") as not all cultures will display AM/PM.

提交回复
热议问题