468,533 Members | 1,909 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,533 developers. It's quick & easy.

DateTime DeSerialization problem

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

Jun 18 '07 #1
9 9033
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]
- mv*@spam.guard.caspershouse.com

"Abhishek" <lu***********@gmail.comwrote in message
news:11**********************@q69g2000hsb.googlegr oups.com...
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

Jun 18 '07 #2
On Jun 18, 8:08 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
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]
- m...@spam.guard.caspershouse.com

"Abhishek" <luckyabhis...@gmail.comwrote in message

news:11**********************@q69g2000hsb.googlegr oups.com...
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

Jun 18 '07 #3
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]
- mv*@spam.guard.caspershouse.com

"Abhishek" <lu***********@gmail.comwrote in message
news:11**********************@n60g2000hse.googlegr oups.com...
On Jun 18, 8:08 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
> 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]
- m...@spam.guard.caspershouse.com

"Abhishek" <luckyabhis...@gmail.comwrote in message

news:11**********************@q69g2000hsb.googleg roups.com...
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

Jun 18 '07 #4
On Jun 18, 8:58 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
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]
- m...@spam.guard.caspershouse.com

"Abhishek" <luckyabhis...@gmail.comwrote in message

news:11**********************@n60g2000hse.googlegr oups.com...
On Jun 18, 8:08 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
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]
- m...@spam.guard.caspershouse.com
"Abhishek" <luckyabhis...@gmail.comwrote in message
>news:11**********************@q69g2000hsb.googleg roups.com...
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

Jun 18 '07 #5
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]
- mv*@spam.guard.caspershouse.com

"Abhishek" <lu***********@gmail.comwrote in message
news:11*********************@q75g2000hsh.googlegro ups.com...
On Jun 18, 8:58 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
> 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]
- m...@spam.guard.caspershouse.com

"Abhishek" <luckyabhis...@gmail.comwrote in message

news:11**********************@n60g2000hse.googleg roups.com...
On Jun 18, 8:08 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
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]
- m...@spam.guard.caspershouse.com
>"Abhishek" <luckyabhis...@gmail.comwrote in message
>>news:11**********************@q69g2000hsb.google groups.com...
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

Jun 18 '07 #6
On Jun 18, 9:48 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
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]
- m...@spam.guard.caspershouse.com

"Abhishek" <luckyabhis...@gmail.comwrote in message

news:11*********************@q75g2000hsh.googlegro ups.com...
On Jun 18, 8:58 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
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]
- m...@spam.guard.caspershouse.com
"Abhishek" <luckyabhis...@gmail.comwrote in message
>news:11**********************@n60g2000hse.googleg roups.com...
On Jun 18, 8:08 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
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]
- m...@spam.guard.caspershouse.com
"Abhishek" <luckyabhis...@gmail.comwrote in message
>news:11**********************@q69g2000hsb.googleg roups.com...
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

Jun 18 '07 #7
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]
- mv*@spam.guard.caspershouse.com

"Abhishek" <lu***********@gmail.comwrote in message
news:11**********************@w5g2000hsg.googlegro ups.com...
On Jun 18, 9:48 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
>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]
- m...@spam.guard.caspershouse.com

"Abhishek" <luckyabhis...@gmail.comwrote in message

news:11*********************@q75g2000hsh.googlegr oups.com...
On Jun 18, 8:58 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
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]
- m...@spam.guard.caspershouse.com
>"Abhishek" <luckyabhis...@gmail.comwrote in message
>>news:11**********************@n60g2000hse.google groups.com...
On Jun 18, 8:08 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
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]
- m...@spam.guard.caspershouse.com
>"Abhishek" <luckyabhis...@gmail.comwrote in message
>>news:11**********************@q69g2000hsb.google groups.com...
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

Jun 18 '07 #8
On Mon, 18 Jun 2007 06:01:02 -0700, Abhishek <lu***********@gmail.com>
wrote:
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
Jun 18 '07 #9
On Jun 18, 11:04 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Mon, 18 Jun 2007 06:01:02 -0700, Abhishek <luckyabhis...@gmail.com>
wrote:
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
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

Jun 19 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Snowman | last post: by
3 posts views Thread by parrot toes | last post: by
9 posts views Thread by Phil B | last post: by
3 posts views Thread by Zachary Turner | last post: by
1 post views Thread by =?Utf-8?B?YXZucmFv?= | last post: by
7 posts views Thread by Looch | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.