Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / October 2003

Tip: Looking for answers? Try searching our database.

xs:dateTime <-> DateTime ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jens Weiermann - 28 Oct 2003 10:43 GMT
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!
Jens
Martin Honnen - 28 Oct 2003 12:54 GMT
> 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?

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);
  }
}
Signature


    Martin Honnen
    http://JavaScript.FAQTs.com/

Jens Weiermann - 28 Oct 2003 16:25 GMT
Hi Martin,

> 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: [Snip]

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!
Jens
Martin Honnen - 29 Oct 2003 15:18 GMT
> 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...

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

Signature

    Martin Honnen
    http://JavaScript.FAQTs.com/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.