XmlConvert.ToDateTimeOffset Method (String)
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Converts the supplied String to a DateTimeOffset equivalent.
Assembly: System.Xml (in System.Xml.dll)
Parameters
- s
- Type: System.String
The string to convert.
Note The string must conform to a subset of the W3C Recommendation for the XML dateTime type. For more information see XML Schema Part 2: Datatypes.
| Exception | Condition |
|---|---|
| ArgumentNullException | s is Nothing. |
| ArgumentOutOfRangeException | The argument passed to this method is outside the range of allowable values. For information about allowable values, see DateTimeOffset. |
| FormatException | The argument passed to this method does not conform to a subset of the W3C Recommendations for the XML dateTime type. For more information see XML Schema Part 2: Datatypes. |
Dim xmlString As String = _
"<?xml version='1.0'?>" & _
"<transactions>" & _
"<transaction>" & _
"<id>123456789</id>" & _
"<amount>1.00</amount>" & _
"<currency>USD</currency>" & _
"<time>2007-08-03T22:05:13-07:00</time>" & _
"</transaction>" & _
"</transactions>"
' Create an XmlReader
Using reader As XmlReader = XmlReader.Create(New StringReader(xmlString))
reader.ReadToFollowing("time")
Dim time As String = reader.ReadElementContentAsString()
' Read the element contents as a string and covert to DateTimeOffset type
' The format of time must be a subset of the W3C Recommendation for the XML dateTime type
Dim transaction_time As DateTimeOffset = XmlConvert.ToDateTimeOffset(time)
OutputTextBlock.Text = transaction_time.ToString()
End Using