Parse string in HH.mm format to TimeSpan

后端 未结 6 1596
栀梦
栀梦 2020-12-06 03:57

I\'m using .NET framework v 3.5 and i need to parse a string representing a timespan into TimeSpan object.

The problem is that

6条回答
  •  长情又很酷
    2020-12-06 04:35

    For .Net 3.5 you may use DateTime.ParseExact and use TimeOfDay property

    string timestring = "12.30";
    TimeSpan ts = DateTime.ParseExact(
                                      timestring, 
                                      "HH.mm", 
                                      CultureInfo.InvariantCulture
                                      ).TimeOfDay;
    

提交回复
热议问题