I am getting a System.FormatException
when I try to do the following (as an example):
TimeSpan ts = XmlConvert.ToTimeSpan("P72H");
I've investigated the ISO8601 Standard and it seems to be correct, but I cannot get it to parse hours without throwing an exception, no matter what I do.
Thanks!
EDIT:
Exception detail:
System.FormatException was unhandled by user code
HResult=-2146233033
Message=The string 'P72H' is not a valid TimeSpan value.
Source=System.Xml
You need to add the Time separator to your string. Try this:
See the duration specification - http://www.w3.org/TR/xmlschema-2/#duration
Please use the following format for
System.Xml.XmlConvert.ToTimeSpan("PnYnMnDTnHnMnS")
.P - The designator must be placed before date format.
nY - Number of years, ex: 2Y
nM - Number of months ex: 4M
nD - Number of Days ex: 6D
T - The designator that must be placed before the time format
nH - Number of Hours ex: 8H
nM - Number of Minutes ex: 12M
nS - Number of seconds ex: 14S
System.Xml.XmlConvert.ToTimeSpan("P2Y4M6DT8H14M18S")
Here, the confusion part with Month and Minutes have the same letter to denote, but the designator usage makes them separate to understand easily.
You must have missed something in the standard. The following:
gives me the string
PT12H
. So it seems like the time portion needs to be prefixed with aT
. And the following parses correctly:(To a
TimeSpan
that stringifies to1.01:00:00
.)