Reputation: 25
here is my problem using data from a xml-webinterface.
The interface provides me with correct data with lots of datablocks like this one:
<item>
<date>2011-01-19T09:02:00+01:00</date>
<open>46.625</open>
<high>46.625</high>
<low>46.62</low>
<close>46.62</close>
<volume>827</volume>
<count>2</count>
<type>TRADE</type>
</item>
The .Net XML-Decoder (System.XML.Serialisation.XmlSerializer) parses this (according to my xsd sceme) into an object containing a "date" attribute.
Here is a code snipped generated from the xsd:
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] public partial class TimeseriesElement {
private System.DateTime dateField; /// <remarks/> public System.DateTime date { get { return this.dateField; } set { this.dateField = value; } } }
There is one derivation from this containing the other values. Nothing interesting to see here, i guess.... The problem for me is that the information, regarding the timezone, is already gone. Yes, the timestamp is correctly modified to the currently active Timezone the system is running in. And yes, this only occures when the user is in a different timezone than +1.
I dont want that, at last not always. Most of the time i am fine with this, but there are cases where i dont want to change the timestamp and use it in its native (+1) timezone. Sadly i loose the information in what timezone the timestamp was delivered (or i did not found a way to extract this information after the parsing took effect), so i cannot alter the timestamp to make it fit my needs again.
Any Ideas? Oh, one more thing. Changing the xml is not an option, so i have to take care of this problem on my side.
edit: typos & answers to the comments
Upvotes: 1
Views: 232
Reputation: 588
Try changing your .NET code to parse it as a DateTimeOffset rather than a DateTime:
private System.DateTimeOffset dateField;
/// <remarks/>
public System.DateTimeOffset date {
get {
return this.dateField;
}
set {
this.dateField = value;
}
}
The DateTimeOffset structure should preserve the offset of the original time.
thanks, mark
Upvotes: 4