如何在VB.Net中将ISO 8601持续时间转换为TimeSpan? [英] How to Convert ISO 8601 Duration to TimeSpan in VB.Net?
问题描述
是否存在一个标准库方法,该方法会将标准ISO 8601持续时间(在XSD中也以 duration
类型使用)的持续时间转换为.NET格式的字符串Timespan对象?
Is there a standard library method that converts a string that has duration in the standard ISO 8601 Duration (also used in XSD for its duration
type) format into the .NET TimeSpan object?
例如,将代表一小时持续时间的P0DT1H0M0S转换为New TimeSpan(0,1,0,0,0)。
For example, P0DT1H0M0S which represents a duration of one hour, is converted into New TimeSpan(0,1,0,0,0).
确实存在一个反向转换器,其工作方式如下:
Xml.XmlConvert.ToString(New TimeSpan(0,1,0,0,0))
上面的表达式将返回P0DT1H0M0S。
A Reverse converter does exist which works as follows: Xml.XmlConvert.ToString(New TimeSpan(0,1,0,0,0)) The above expression will return P0DT1H0M0S.
推荐答案
这将从xs:duration转换为TimeSpan:
This will convert from xs:duration to TimeSpan:
System.Xml.XmlConvert.ToTimeSpan("P0DT1H0M0S")
请参见 http:// msdn .microsoft.com / en-us / library / system.xml.xmlconvert.totimespan.aspx
这篇关于如何在VB.Net中将ISO 8601持续时间转换为TimeSpan?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!