XmlConvert::ToDateTimeOffset Method (String^, array<String^>^)
Converts the supplied String to a DateTimeOffset equivalent.
Assembly: System.Xml (in System.Xml.dll)
Parameters
- s
-
Type:
System::String^
The string to convert.
- formats
-
Type:
array<System::String^>^
An array of formats from which s can be converted. Each format in formats can be any subset of the W3C Recommendation for the XML dateTime type. (For more information see http://www.w3.org/TR/xmlschema-2/#dateTime.) The string s is validated against one of these formats.
If the offset specified within the input string will cause an overflow in the deserialized representation of the DateTimeOffset, a FormatException is thrown.
When more than seven digits are specified for fractional seconds, the value is rounded. For example, 00000004 becomes 0000000 and 00000005 becomes 0000001.
The following example demonstrates how to read a string from an XML file and use the ToDateTimeOffset method to convert the string to a DateTimeOffset type. The input string must validate against one of the specified formats before being converted.
The example uses the transactions.xml file.
<?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>
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1