Cast the value of this XAttribute to a DateTimeOffset.
Public Shared Narrowing Operator CType ( _ element As XElement _ ) As DateTimeOffset
public static explicit operator DateTimeOffset ( XElement element )
static explicit operator DateTimeOffset ( XElement^ element )
F# does not support the declaration of new casting operators.
The element does not contain a valid DateTimeOffset value.
The element parameter is nullNothingnullptra null reference (Nothing in Visual Basic).
This conversion operator uses the XmlConvert class to do the conversion.
The following example creates an element with date and time content. It then casts to DateTimeOffset to retrieve the value.
XElement root = new XElement("Root", new XElement("Child", new DateTimeOffset(new DateTime(2006, 10, 6, 12, 30, 0))) ); Console.WriteLine(root); DateTimeOffset dt = (DateTimeOffset)root.Element("Child"); Console.WriteLine("dt={0}", dt);
Dim root As XElement = _ <Root> <Child><%= New DateTimeOffset(New DateTime(2006, 10, 6, 12, 30, 0)) %></Child> </Root> Console.WriteLine(root) Dim dt As DateTimeOffset = CType(root.<Child>(0), DateTimeOffset) Console.WriteLine("dt={0}", dt)
This example produces the following output:
<Root> <Child>2006-10-06T12:30:00-07:00</Child> </Root> dt=10/6/2006 12:30:00 PM -07:00
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2