DateTime DeSerialization problem

A

Abhishek

Hi

I am trying to deserialize/ Parse a datetime object with the below
string "2007-05-14T08:00:00.000+02:30" . If i am in GMT + 2.30 time
zone everything's fine however if i am in GMT + 5.30 i get the
DateTime object which represents 11.00 AM.
Now this is perfectly fine as if i go from GMT +2.30 tp GMT + 5.30 ,
8.00 AM becomes 11.00 AM. however this is not what i want to achieve
in my program.
What i want to achieve is to reconstruct a date time object which
gives me the 8.00 AM as clock time.

Any help would be appreciated a lot.

Thanks, Abhishek
 
N

Nicholas Paldino [.NET/C# MVP]

So you want 8 AM no matter what time zone you are in? If that is the
case, then just create a format string when calling ToString which does not
have the timezone information in it (or an offset from GMT), and it should
work.
 
A

Abhishek

So you want 8 AM no matter what time zone you are in? If that is the
case, then just create a format string when calling ToString which does not
have the timezone information in it (or an offset from GMT), and it should
work.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




I am trying to deserialize/ Parse a datetime object with the below
string "2007-05-14T08:00:00.000+02:30" . If i am in GMT + 2.30 time
zone everything's fine however if i am in GMT + 5.30 i get the
DateTime object which represents 11.00 AM.
Now this is perfectly fine as if i go from GMT +2.30 tp GMT + 5.30 ,
8.00 AM becomes 11.00 AM. however this is not what i want to achieve
in my program.
What i want to achieve is to reconstruct a date time object which
gives me the 8.00 AM as clock time.
Any help would be appreciated a lot.
Thanks, Abhishek- Hide quoted text -

- Show quoted text -

Hi Nicholas

It would work as long as i am in GMT + 2.30
As soon as i switch my system time zone to GMT + 5.30 it would start
giving me 11.00 AM which is a problem for me
~Abhishek
 
N

Nicholas Paldino [.NET/C# MVP]

Right, that's because you have the "GMT" part in your string. Create a
format which doesn't have the "GMT" part in it and it should have no choice
but to assume local time.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Abhishek said:
So you want 8 AM no matter what time zone you are in? If that is the
case, then just create a format string when calling ToString which does
not
have the timezone information in it (or an offset from GMT), and it
should
work.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




I am trying to deserialize/ Parse a datetime object with the below
string "2007-05-14T08:00:00.000+02:30" . If i am in GMT + 2.30 time
zone everything's fine however if i am in GMT + 5.30 i get the
DateTime object which represents 11.00 AM.
Now this is perfectly fine as if i go from GMT +2.30 tp GMT + 5.30 ,
8.00 AM becomes 11.00 AM. however this is not what i want to achieve
in my program.
What i want to achieve is to reconstruct a date time object which
gives me the 8.00 AM as clock time.
Any help would be appreciated a lot.
Thanks, Abhishek- Hide quoted text -

- Show quoted text -

Hi Nicholas

It would work as long as i am in GMT + 2.30
As soon as i switch my system time zone to GMT + 5.30 it would start
giving me 11.00 AM which is a problem for me
~Abhishek
 
A

Abhishek

Right, that's because you have the "GMT" part in your string. Create a
format which doesn't have the "GMT" part in it and it should have no choice
but to assume local time.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




So you want 8 AM no matter what time zone you are in? If that is the
case, then just create a format string when calling ToString which does
not
have the timezone information in it (or an offset from GMT), and it
should
work.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi
I am trying to deserialize/ Parse a datetime object with the below
string "2007-05-14T08:00:00.000+02:30" . If i am in GMT + 2.30 time
zone everything's fine however if i am in GMT + 5.30 i get the
DateTime object which represents 11.00 AM.
Now this is perfectly fine as if i go from GMT +2.30 tp GMT + 5.30 ,
8.00 AM becomes 11.00 AM. however this is not what i want to achieve
in my program.
What i want to achieve is to reconstruct a date time object which
gives me the 8.00 AM as clock time.
Any help would be appreciated a lot.
Thanks, Abhishek- Hide quoted text -
- Show quoted text -
Hi Nicholas
It would work as long as i am in GMT + 2.30
As soon as i switch my system time zone to GMT + 5.30 it would start
giving me 11.00 AM which is a problem for me
~Abhishek- Hide quoted text -

- Show quoted text -

Do you mean i should have a string "2007-05-14T08:00:00.000Z" instead
of "2007-05-14T08:00:00.000+02:30" ?

~Abhishek
 
N

Nicholas Paldino [.NET/C# MVP]

Abishek,

That would be UNC time. What about a format of
"2007-05-14T08:00:00.000" or "2007-05-14 08:00:00.000".


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Abhishek said:
Right, that's because you have the "GMT" part in your string. Create
a
format which doesn't have the "GMT" part in it and it should have no
choice
but to assume local time.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




On Jun 18, 8:08 pm, "Nicholas Paldino [.NET/C# MVP]"
So you want 8 AM no matter what time zone you are in? If that is
the
case, then just create a format string when calling ToString which
does
not
have the timezone information in it (or an offset from GMT), and it
should
work.
I am trying to deserialize/ Parse a datetime object with the below
string "2007-05-14T08:00:00.000+02:30" . If i am in GMT + 2.30 time
zone everything's fine however if i am in GMT + 5.30 i get the
DateTime object which represents 11.00 AM.
Now this is perfectly fine as if i go from GMT +2.30 tp GMT + 5.30 ,
8.00 AM becomes 11.00 AM. however this is not what i want to achieve
in my program.
What i want to achieve is to reconstruct a date time object which
gives me the 8.00 AM as clock time.
Any help would be appreciated a lot.
Thanks, Abhishek- Hide quoted text -
- Show quoted text -
Hi Nicholas
It would work as long as i am in GMT + 2.30
As soon as i switch my system time zone to GMT + 5.30 it would start
giving me 11.00 AM which is a problem for me
~Abhishek- Hide quoted text -

- Show quoted text -

Do you mean i should have a string "2007-05-14T08:00:00.000Z" instead
of "2007-05-14T08:00:00.000+02:30" ?

~Abhishek
 
A

Abhishek

Abishek,

That would be UNC time. What about a format of
"2007-05-14T08:00:00.000" or "2007-05-14 08:00:00.000".

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




Right, that's because you have the "GMT" part in your string. Create
a
format which doesn't have the "GMT" part in it and it should have no
choice
but to assume local time.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

On Jun 18, 8:08 pm, "Nicholas Paldino [.NET/C# MVP]"
So you want 8 AM no matter what time zone you are in? If that is
the
case, then just create a format string when calling ToString which
does
not
have the timezone information in it (or an offset from GMT), and it
should
work.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi
I am trying to deserialize/ Parse a datetime object with the below
string "2007-05-14T08:00:00.000+02:30" . If i am in GMT + 2.30 time
zone everything's fine however if i am in GMT + 5.30 i get the
DateTime object which represents 11.00 AM.
Now this is perfectly fine as if i go from GMT +2.30 tp GMT + 5.30 ,
8.00 AM becomes 11.00 AM. however this is not what i want to achieve
in my program.
What i want to achieve is to reconstruct a date time object which
gives me the 8.00 AM as clock time.
Any help would be appreciated a lot.
Thanks, Abhishek- Hide quoted text -
- Show quoted text -
Hi Nicholas
It would work as long as i am in GMT + 2.30
As soon as i switch my system time zone to GMT + 5.30 it would start
giving me 11.00 AM which is a problem for me
~Abhishek- Hide quoted text -
- Show quoted text -
Do you mean i should have a string "2007-05-14T08:00:00.000Z" instead
of "2007-05-14T08:00:00.000+02:30" ?
~Abhishek- Hide quoted text -

- Show quoted text -

This is kind of tricky. I've this string coming in as part of SOAP
Response in IBF call and i can't change the server part of the
application.
Basically the SOAP Serializer on the server side serializes a Java
Calendar object to achieve this result and i definitely have very
little control on that serializer.
Any other way ?

~Abhishek
 
N

Nicholas Paldino [.NET/C# MVP]

Abhishek,

In this case, you will have to take the offset that you are in (+5.5
hours) and subtract it from the offset the time came from (+2.5 hours) for a
difference of -3 hours. You then apply that to the time in local time on
your machine (11 am) and you will get the local time (8 am).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Abhishek said:
Abishek,

That would be UNC time. What about a format of
"2007-05-14T08:00:00.000" or "2007-05-14 08:00:00.000".

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




On Jun 18, 8:58 pm, "Nicholas Paldino [.NET/C# MVP]"
Right, that's because you have the "GMT" part in your string.
Create
a
format which doesn't have the "GMT" part in it and it should have no
choice
but to assume local time.

On Jun 18, 8:08 pm, "Nicholas Paldino [.NET/C# MVP]"
So you want 8 AM no matter what time zone you are in? If that
is
the
case, then just create a format string when calling ToString which
does
not
have the timezone information in it (or an offset from GMT), and it
should
work.
I am trying to deserialize/ Parse a datetime object with the
below
string "2007-05-14T08:00:00.000+02:30" . If i am in GMT + 2.30
time
zone everything's fine however if i am in GMT + 5.30 i get the
DateTime object which represents 11.00 AM.
Now this is perfectly fine as if i go from GMT +2.30 tp GMT +
5.30 ,
8.00 AM becomes 11.00 AM. however this is not what i want to
achieve
in my program.
What i want to achieve is to reconstruct a date time object which
gives me the 8.00 AM as clock time.
Any help would be appreciated a lot.
Thanks, Abhishek- Hide quoted text -
- Show quoted text -
Hi Nicholas
It would work as long as i am in GMT + 2.30
As soon as i switch my system time zone to GMT + 5.30 it would start
giving me 11.00 AM which is a problem for me
~Abhishek- Hide quoted text -
- Show quoted text -
Do you mean i should have a string "2007-05-14T08:00:00.000Z" instead
of "2007-05-14T08:00:00.000+02:30" ?
~Abhishek- Hide quoted text -

- Show quoted text -

This is kind of tricky. I've this string coming in as part of SOAP
Response in IBF call and i can't change the server part of the
application.
Basically the SOAP Serializer on the server side serializes a Java
Calendar object to achieve this result and i definitely have very
little control on that serializer.
Any other way ?

~Abhishek
 
P

Peter Duniho

I am trying to deserialize/ Parse a datetime object with the below
string "2007-05-14T08:00:00.000+02:30" . If i am in GMT + 2.30 time
zone everything's fine however if i am in GMT + 5.30 i get the
DateTime object which represents 11.00 AM.
Now this is perfectly fine as if i go from GMT +2.30 tp GMT + 5.30 ,
8.00 AM becomes 11.00 AM. however this is not what i want to achieve
in my program.
What i want to achieve is to reconstruct a date time object which
gives me the 8.00 AM as clock time.

Maybe you can clarify the behavior you want. If you are not in timezone
+02:30, and you want the time displayed in your local time, it's not clear
to me why you want the final display to be shown as 08:00:00 in your local
time zone. That's not the same time that you were given in the string.

IMHO, one of the cleanest ways to deal with this is to parse the time as
universal time, and then convert to local or to other timezones as needed
(which may not be necessary at all, depending on what you're doing with
it).

Use the DateTimeStyles.AdjustToUniversal as a parameter to
DateTime.Parse() to have the timezone offset included in the parsing and
applied so that the resulting DateTime object is a Utc type. At that
point, you have the correct time represented as Universal time. Then you
can convert it as appropriate to a different timezone (for example, the
local time, or the original timezone of offset +02:30).

Pete
 
A

Abhishek

Maybe you can clarify the behavior you want. If you are not in timezone
+02:30, and you want the time displayed in your local time, it's not clear
to me why you want the final display to be shown as 08:00:00 in your local
time zone. That's not the same time that you were given in the string.

IMHO, one of the cleanest ways to deal with this is to parse the time as
universal time, and then convert to local or to other timezones as needed
(which may not be necessary at all, depending on what you're doing with
it).

Use the DateTimeStyles.AdjustToUniversal as a parameter to
DateTime.Parse() to have the timezone offset included in the parsing and
applied so that the resulting DateTime object is a Utc type. At that
point, you have the correct time represented as Universal time. Then you
can convert it as appropriate to a different timezone (for example, the
local time, or the original timezone of offset +02:30).

Pete

Hi Pete

I understand what you are saying however i can;t really do what you
are suggesting. The reason being that i am working on an application
which is timezone aware on the frontend e.g. Outlook however my
backend is time zone unaware.
Now to overcome this limitation what we've decided is to actually
transfer the date time over the wire in the above format where the
bacend only stores the clock time. Now since .NET serializer always
serializes the DateTime in the above format my problem is solved.
however when i need to display the time to the user and if he has
changed his time zone i still need to display the clock time which has
been recorded in the backend.
I can't really work in all UTC because we've plans to modify our
backend to be timezone aware and consider the timezones as well. So to
maintain the forward compatibility i need to make sure that actual
stuff goes over the wire.
~Abhishek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top