我用 .NET框架V 3.5 ,我需要分析一个字符串,再presenting时间跨度为时间跨度
对象。
I'm using .NET framework v 3.5 and i need to parse a string representing a timespan into TimeSpan
object.
问题是,点分离器是用来代替结肠...例如 13.00
或 22.30
The problem is that dot separator is used instead of colon... For example 13.00
, or 22.30
所以,我想知道如果我要更换
与:
或有一个更清洁的方式来获得此。
So I'm wondering if I have to replace .
with :
or there is a more clean way to obtain this.
解析出的DateTime
和使用它的的TimeOfDay
属性,它是一个时间跨度
结构:
Parse out the DateTime
and use it's TimeOfDay
property which is a TimeSpan
structure:
string s = "17.34";
var ts = DateTime.ParseExact(s, "HH.mm", CultureInfo.InvariantCulture).TimeOfDay;