tags:

views:

1501

answers:

1

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?

For example, P0DT1H0M0S which represents a duration of one hour, is converted into New TimeSpan(0,1,0,0,0).

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.

+4  A: 

This will convert from xs:duration to TimeSpan:

System.Xml.XmlConvert.ToTimeSpan("P0DT1H0M0S")

See http://msdn.microsoft.com/en-us/library/system.xml.xmlconvert.totimespan.aspx