Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateTime Serialization 1

Status
Not open for further replies.

MadJock

Programmer
May 25, 2001
318
GB
Hi All,

Hopefully someone can provide some help with this!

I am calling a web API (not a asmx web services - I'm ussing the HttpRequest classes) and the response returns some XML.

The API belongs to a 3rd party in Holland.

I've created classes that 'map' to the XML using an XSD file provided by the thrid party. My problem is when dates are returned to me.

Looking at the XML returned a time looks like this: 00:00:00+02:00

When I deserialize this (using standard .Net deserialization), the time in my class looks like:
23:00:00

If I examine the DateTime in the debug inspector, the DateTimeKind is 'Local' - I think I want UTC, but not sure if I'm correct here or how to achieve it!

Any help / pointers / samples would be greatly appreciated!

I'm using .Net 2.0 - if anyone needs the code, please let me know.

Thanks,

Graeme


"Just beacuse you're paranoid, don't mean they're not after you
 
so what exactly is the problem?
xml stores dates as universal time. unless 00:00:00+02:00
is not 23:00:00 (11pm) everything is working properly. how the datetime is displayed is irrelvant.



Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hi jmeckley, thanks for the response.

The issue is, the API call I'm making is of the 'GetTemplate' type. It gives me a basic object that I then go through and add values to before resubmitting to the API.

When it goes back to the API, the server there is in a different timezone (CET). That's why I need to keep the 00:00:00+2

Thanks,

Graeme


"Just beacuse you're paranoid, don't mean they're not after you
 
how the date is displayed in the debugger doesn't effect the actual time. if you want to confirm the time in the debugger is correct
Code:
System.Diagonostics.Debug.Write("Local {0} is UTC {1}", DateTime.Now, DateTime.Now.ToUniversalTime());

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Right you are - my bad :D

Thanks for your help.

"Just beacuse you're paranoid, don't mean they're not after you
 
Looking at the XML returned a time looks like this: 00:00:00+02:00

Sounds like someone actually read the W3C XML spec.
:)

Dates in XML use ISO-8601 format:

Use the XmlConvert class to turn them into a DateTime.

Chip H.


____________________________________________________________________
www.chipholland.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top