How to Convert string “07:35” (HH:MM) to TimeSpan

后端 未结 4 512
我寻月下人不归
我寻月下人不归 2020-11-28 09:19

I would like to know if there is a way to convert a 24 Hour time formatted string to a TimeSpan.

Right now I have a \"old fashion style\":

string str         


        
4条回答
  •  感动是毒
    2020-11-28 09:39

    You can convert the time using the following code.

    TimeSpan _time = TimeSpan.Parse("07:35");
    

    But if you want to get the current time of the day you can use the following code:

    TimeSpan _CurrentTime = DateTime.Now.TimeOfDay;
    

    The result will be:

    03:54:35.7763461
    

    With a object cantain the Hours, Minutes, Seconds, Ticks and etc.

提交回复
热议问题