From XmlConvert.ToTimeSpan
method
Parameters
s
Type: System.String
The string to convert. The string format must conform to the W3C XML Schema Part 2: Datatypes recommendation for duration.
And Duration section
The lexical representation for duration is the [ISO 8601] extended
format PnYn MnDTnH nMnS
, where nY
represents the number of years, nM
the number of months, nD
the number of days, 'T'
is the date/time
separator, nH
the number of hours, nM
the number of minutes and nS
the
number of seconds.
From ISO 8601 Date and Time Formats
In the lexical format for duration the following characters are also
used as designators and appear as themselves in lexical formats:
- P -- is used as the time duration designator, preceding a data element representing a given duration of time.
- Y -- follows the number of years in a time duration.
- M -- follows the number of months or minutes in a time duration.
- D -- follows the number of days in a time duration.
- H -- follows the number of hours in a time duration.
- S -- follows the number of seconds in a time duration.
As far as I can see, there is no W
as a duration format in XML specification.
This works for example;
TimeSpan ts = XmlConvert.ToTimeSpan("P2M5D");
