473,382 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Want to get rid of UTC offset in serialization of DateTime

Hi everyone!

In the following code we get a UTC offset in xml. Since I want my WAP users in
UTC+02:00 to see data on a server in some US time zone, a lot of confusion will
be created from this behavior. Either I use .NET logic on the server and get
server local time or I create xhtml pages directly from serialized objects.
Eitherway I'll have to write my own logic to take care of utc offset. Is it
possible to override XmlSerializer so what my local desktop user send to the
webservice is saved on the server without utc offset? That way, the time that is

local to my users will be saved on the server. I guess it's kind of hard to
tweak ASP.NET WebService infrastructure into this. On the other hand it feels
like bad manners to change my xsd:dateTime values to xsd:string because of what
i discover about .NET. /Regards Bjorn

public class SomeDates {
public DateTime Summer;
public DateTime Winter;
}

public static void TestSomeDates() {
SomeDates obj = new SomeDates();
obj.Winter = DateTime.Parse("2003-12-22 12:32:45");
obj.Summer = DateTime.Parse("2004-08-05 18:45:21");
XmlSerializer serializer = new XmlSerializer(typeof(SomeDates));
StreamWriter writer = new StreamWriter("obj.xml");
serializer.Serialize(writer, obj);
writer.Close();
}

Nov 12 '05 #1
2 7238
This example shows some of the possibilities.
http://www.winisp.net/cheeso/srcview...le=DateTime.cs

-D
"BjörnHolmberg" <bj**********************@suliteAndthiSlma.com> wrote in
message news:41***************@suliteAndthiSlma.com...
Hi everyone!

In the following code we get a UTC offset in xml. Since I want my WAP users in UTC+02:00 to see data on a server in some US time zone, a lot of confusion will be created from this behavior. Either I use .NET logic on the server and get server local time or I create xhtml pages directly from serialized objects. Eitherway I'll have to write my own logic to take care of utc offset. Is it possible to override XmlSerializer so what my local desktop user send to the webservice is saved on the server without utc offset? That way, the time that is
local to my users will be saved on the server. I guess it's kind of hard to tweak ASP.NET WebService infrastructure into this. On the other hand it feels like bad manners to change my xsd:dateTime values to xsd:string because of what i discover about .NET. /Regards Bjorn

public class SomeDates {
public DateTime Summer;
public DateTime Winter;
}

public static void TestSomeDates() {
SomeDates obj = new SomeDates();
obj.Winter = DateTime.Parse("2003-12-22 12:32:45");
obj.Summer = DateTime.Parse("2004-08-05 18:45:21");
XmlSerializer serializer = new XmlSerializer(typeof(SomeDates));
StreamWriter writer = new StreamWriter("obj.xml");
serializer.Serialize(writer, obj);
writer.Close();
}


Nov 12 '05 #2
Based on the ideas Dino sent me, I managed to find out a working solution to my
problem. I also realised that it's possible to keep xsd:dateTime in my schema and to
use it in a Web Service. Only drawback is that the wsdl can't be autogenerated.
Here's roughly what I came up with:

public class Approval {
public string Manager;
public int ProjectId;
public string Location;
public string ApprovedAt;

[XmlIgnore]
public DateTime LocalApprovedAt {
get {
return DateTime.Parse(ApprovedAt);
}
set {
ApprovedAt = value.ToString("yyyy-MM-ddTHH:mm:ss");
}
}
}

public static void TestApproval() {
Approval obj = new Approval();
obj.Manager = "Smith";
obj.ProjectId = 1234;
obj.Location = "Pleasantville";
obj.LocalApprovedAt = DateTime.Parse("2002-02-28 13:48:00");
XmlSerializer serializer = new XmlSerializer(typeof(Approval));
StreamWriter writer = new StreamWriter("obj.xml");
serializer.Serialize(writer, obj);
writer.Close();
}

/Bjorn

"Dino Chiesa [Microsoft]" wrote:
This example shows some of the possibilities.
http://www.winisp.net/cheeso/srcview...le=DateTime.cs

-D

"BjörnHolmberg" <bj**********************@suliteAndthiSlma.com> wrote in
message news:41***************@suliteAndthiSlma.com...
Hi everyone!

In the following code we get a UTC offset in xml. Since I want my WAP

users in
UTC+02:00 to see data on a server in some US time zone, a lot of confusion

will
be created from this behavior. Either I use .NET logic on the server and

get
server local time or I create xhtml pages directly from serialized

objects.
Eitherway I'll have to write my own logic to take care of utc offset. Is

it
possible to override XmlSerializer so what my local desktop user send to

the
webservice is saved on the server without utc offset? That way, the time

that is

local to my users will be saved on the server. I guess it's kind of hard

to
tweak ASP.NET WebService infrastructure into this. On the other hand it

feels
like bad manners to change my xsd:dateTime values to xsd:string because of

what
i discover about .NET. /Regards Bjorn

public class SomeDates {
public DateTime Summer;
public DateTime Winter;
}

public static void TestSomeDates() {
SomeDates obj = new SomeDates();
obj.Winter = DateTime.Parse("2003-12-22 12:32:45");
obj.Summer = DateTime.Parse("2004-08-05 18:45:21");
XmlSerializer serializer = new XmlSerializer(typeof(SomeDates));
StreamWriter writer = new StreamWriter("obj.xml");
serializer.Serialize(writer, obj);
writer.Close();
}



Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: ron | last post by:
Hi, I have class object that i serialize using the System.Xml.Serialization class. Intermittently the object is not getting serialized correctly, using System.Xml.Serialization classes....
11
by: ajou_king | last post by:
I was running some tests on my Win32 1GHZ processor to see how long it would take to transmit objects numerous times via TCP/IP using C# ..NET Remoting vs the C++ trustworthy method of binary...
3
by: AnkitAsDeveloper [Ankit] | last post by:
Hi i am serializing a 'ref struct' object as follows : private: void Seri( String ^path, Object^ obj ) { FileStream^ fileStrm ; try { //Serialize entire object into Binary stream
0
by: BjörnHolmberg | last post by:
Hi everyone! In the following code we get a UTC offset in xml. Since I want my WAP users in UTC+02:00 to see data on a server in some US time zone, a lot of confusion will be created from this...
5
by: ns21 | last post by:
Our application is windows desktop application. We are using VS.Net 2003, C#, Framework 1.1, SQL 2000. We use webservices to add/update/select objects. We are using XML Serialization. Following is...
2
by: Jon Jon | last post by:
1st please forgive me if I posted this to the wrong news group(s), news group guidance would be appreciated. Question: I have the following sample class generated from XSD.exe (Vs 2005). I...
7
by: =?Utf-8?B?U3R1?= | last post by:
I have a ASP.NET Ajax app (using client library) calling ASP.NET Ajax-enabled web services. We are making use of the javascript proxies generated by ASP.NET Ajax. The problem we have is that the...
5
by: Nikola Skoric | last post by:
I ran in Mono a program developed on .NET Framework 2.0 and it ran OK until I tried to desirialize a object. There the program died abruptly dumping this: System.ArgumentOutOfRangeException:...
1
by: Simon429 | last post by:
Hi, I got a client application where it calls the webservices to save and retreive dates from an Oracle database. 1 problem I've encountered is that when a user select a certain date in the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.