Groups | Blog | Home
all groups > dotnet xml > october 2003 >

dotnet xml : xs:dateTime <-> DateTime ?


Jens Weiermann
10/28/2003 10:43:08 AM
Hi!

I'm reading data from an XML file using the XmlDocument class. Some
elements are of type xs:dateTime. Is there a way to convert a xs:dateTime
value to a standard DateTime object?

Thanks!
Martin Honnen
10/28/2003 12:54:21 PM


[quoted text, click to view]

Look at XmlConvert which has a ToString(DateTime) method to convert a
..NET DateTime to a string complying with xs:dateTime and a method
ToDateTime(string) to convert a xs:dateTime string into a .NET DateTime
object:

using System;
using System.Xml;

public class Test20031028 {
public static void Main (string[] args) {
DateTime now = DateTime.Now;
System.Console.WriteLine("now: " + now);
string schemaDateTime = XmlConvert.ToString(now);
System.Console.WriteLine("XmlConvert.ToString(now): " +
schemaDateTime);
DateTime dt = XmlConvert.ToDateTime(schemaDateTime);
System.Console.WriteLine(dt);
}
}
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jens Weiermann
10/28/2003 4:25:42 PM
Hi Martin,

[quoted text, click to view]

thanks, that did it! Now, is there something similar for the xs:duration
data type? I already found the TimeSpan thingie, but that doesn't seem to
cover xs:duration...

Thanks again!
Martin Honnen
10/29/2003 3:18:00 PM


[quoted text, click to view]

XmlConvert also has methods ToString(TimeSpan) and ToTimeSpan(string)
thus I think TimeSpan covers xs:duration.

--

Martin Honnen
http://JavaScript.FAQTs.com/
AddThis Social Bookmark Button