Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How does Deserialize handle date time?
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Divers
Thread ID:
01106771
Message ID:
01107667
Vues:
14
This message has been marked as the solution to the initial question of the thread.
Hi Dawa,

Did you ever get this to work? I just tried it and it works fine for me. Could you post more of your code? (like how you got the XML string or stream or whatever you used). Here's the little test I used that worked:

First I instantiated the class, set the MyDate property to 3/21/2006 12:25:00, and wrote it out to an XML file.
MyCustomClass o = new MyCustomClass();
o.MyDate = new DateTime(2006, 3, 21, 12,25,0);
XmlSerializer se = new XmlSerializer(typeof(MyCustomClass));
XmlWriter writer = new XmlTextWriter("MyTest.XML", System.Text.Encoding.UTF8);
se.Serialize(writer, o);
writer.Close();
I set a breakpoint at this point in the program, and then up opened the created file in Notepad and changed "2006-03-21T12:25:00.0000000-08:00" to "2006-03-21T12:25:00.0000000-05:00". I then read it back in and deserialized. My MessageBox shows as 9:25, as it should. I tried both a StreamReader and an XmlTextReader. Both seemed to work fine.
//StreamReader xr = new StreamReader("MyTest.XML");
XmlReader xr = new XmlTextReader("MyTest.XML");

MyCustomClass mc = (MyCustomClass)se.Deserialize(xr);
MessageBox.Show(mc.MyDate.ToShortTimeString());
~~Bonnie



>Hi all,
>
>My code deserializes an XML string as follows:
>
>///XML <CreateDateTime>2006-03-21T12:25:30-05:00</CreateDateTime>
>XmlSerializer se = new XmlSerializer(typeof(MyClass));
>MyClass mc = se.Deserialize(xmlStream) as MyClass;
>//mc.CreateDateTime == {03/21/2006 12:25:30 PM}
>
>When the XML was deserialized, it seemed to have ignored the GMT bias.
>Pacific Time bias is GMT-08.00, so mc.CreateDateTime should be {03/21/2006 9:25:30 AM}.
>
>What do I need to do have the Desializer convert the date to local time properly.
>
>TIA
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform