473,406 Members | 2,698 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,406 software developers and data experts.

DateTime time zone conversions not required !

Would appreciate some insight into how people are dealing with the
implicit conversion of timezones that .NET does.

If a server in one timezone delivers up a typed dataset to a component
in another (winform for example) then the timezone conversion takes
place. This is a pain if you are doing date based calculations on the
client using input in one timezone and data from another. (Take one
hour off a CET time and you go a day back in terms of days...)

What are people doing to conteract this? What are some sample
strategies? Any sample code to simply STOP this would help, but I
suspect there are more far reaching implications...

Thanks
Nov 15 '05 #1
4 15220
GiriT,

.NET shouldn't be doing anything to the dates to change them when you
are returning (and I have heard of no such feature). Is it possible that
this is happening on the database level, or some other level which you are
not aware of?

To get around things like this, I make sure that all dates stored in the
database are in UTC, and I do modification on them locally if need be.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

"GiriT" <gt******@prologis.com> wrote in message
news:f1**************************@posting.google.c om...
Would appreciate some insight into how people are dealing with the
implicit conversion of timezones that .NET does.

If a server in one timezone delivers up a typed dataset to a component
in another (winform for example) then the timezone conversion takes
place. This is a pain if you are doing date based calculations on the
client using input in one timezone and data from another. (Take one
hour off a CET time and you go a day back in terms of days...)

What are people doing to conteract this? What are some sample
strategies? Any sample code to simply STOP this would help, but I
suspect there are more far reaching implications...

Thanks

Nov 15 '05 #2

Hi ,

The TimeZone converstion at lease take place when you serialize the
DateTime object.
You can just follow Nicholas' suggestion, convert the DateTime object into
UTC.
I think you also can convert your DateTime object into a string and after
received construct a new DateTime object.

Hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: gt******@prologis.com (GiriT)
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Subject: DateTime time zone conversions not required !
| Date: 10 Oct 2003 05:25:45 -0700
| Organization: http://groups.google.com
| Lines: 14
| Message-ID: <f1**************************@posting.google.com >
| NNTP-Posting-Host: 193.67.177.98
| Content-Type: text/plain; charset=ISO-8859-1
| Content-Transfer-Encoding: 8bit
| X-Trace: posting.google.com 1065788745 12856 127.0.0.1 (10 Oct 2003
12:25:45 GMT)
| X-Complaints-To: gr**********@google.com
| NNTP-Posting-Date: Fri, 10 Oct 2003 12:25:45 +0000 (UTC)
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!t-onlin
e.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!postnew s1.google.com!no
t-for-mail
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:190527
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Would appreciate some insight into how people are dealing with the
| implicit conversion of timezones that .NET does.
|
| If a server in one timezone delivers up a typed dataset to a component
| in another (winform for example) then the timezone conversion takes
| place. This is a pain if you are doing date based calculations on the
| client using input in one timezone and data from another. (Take one
| hour off a CET time and you go a day back in terms of days...)
|
| What are people doing to conteract this? What are some sample
| strategies? Any sample code to simply STOP this would help, but I
| suspect there are more far reaching implications...
|
| Thanks
|

Nov 15 '05 #3
What is interesting is the following:

The database has a date as 10 Oct 1999 00:00 (ie midnight)

A webservice in CET (GMT+1) plucks this out of the database into a typed
dataset.

If you go direct to the webservice from a browser and use the VS.NET harness
you see the right date.

A component in a different timezone GMT receives this typed dataset. When
you then access the typed dataset's date field it has become.... 11 Oct
1999 22:00. Now this is strictly speaking correct as that is the time GMT
if you take daylight saving into account...

My problem is that all my dates are in as midnight... I don't care about
the "time" as such so converting to and from UTC is not realistic as the
dates when entered by the user into the system are specified as just dates
not daae and time in their timezone....

Luckily for me .Subtract returns a TimeSpan object, whose Days property is
returning the correct result (can you confirm this ?).

This doesn't resolve whether I should be :

a) Letting dates go in as midnight but then use .ToLocalTime() in the
timezone.
b) Engage in the complexity of dealing with time and convert to UTC on the
way in and ToLocal on the way out..
b) Any other strategy...

Be grateful for any advice on this.
Nov 15 '05 #4

Hi Giri,

I think a sample and easy to implement way of avoiding the timezone
conversion is convert the Datetime object to string, then in client side,
you can again convert the string into DateTime object.
If you want to do the timezone conversion, I think you should store the UTC
in server side and use tolocal method in client side.

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Giri" <gt******@prologis.com>
| References: <f1**************************@posting.google.com >
<Xk**************@cpmsftngxa06.phx.gbl>
| Subject: Re: DateTime time zone conversions not required !
| Date: Tue, 21 Oct 2003 09:21:52 +0100
| Lines: 34
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <ua*************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 193.67.177.98
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:192793
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| What is interesting is the following:
|
| The database has a date as 10 Oct 1999 00:00 (ie midnight)
|
| A webservice in CET (GMT+1) plucks this out of the database into a typed
| dataset.
|
| If you go direct to the webservice from a browser and use the VS.NET
harness
| you see the right date.
|
| A component in a different timezone GMT receives this typed dataset. When
| you then access the typed dataset's date field it has become.... 11 Oct
| 1999 22:00. Now this is strictly speaking correct as that is the time GMT
| if you take daylight saving into account...
|
| My problem is that all my dates are in as midnight... I don't care about
| the "time" as such so converting to and from UTC is not realistic as the
| dates when entered by the user into the system are specified as just dates
| not daae and time in their timezone....
|
| Luckily for me .Subtract returns a TimeSpan object, whose Days property is
| returning the correct result (can you confirm this ?).
|
| This doesn't resolve whether I should be :
|
| a) Letting dates go in as midnight but then use .ToLocalTime() in the
| timezone.
| b) Engage in the complexity of dealing with time and convert to UTC on the
| way in and ToLocal on the way out..
| b) Any other strategy...
|
| Be grateful for any advice on this.
|
|
|

Nov 15 '05 #5

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

Similar topics

4
by: Max M | last post by:
# -*- coding: latin-1 -*- """ I am currently using the datetime package, but I find that the design is oddly asymmetric. I would like to know why. Or perhaps I have misunderstood how it...
2
by: Daniel Jung | last post by:
Hi 1088553069 => Wed Jun 30 01:51:22 2004 CEST I can do the time INT string substitution, but I want a set of "country codes", in order for my users to be able to pick their own preferences....
3
by: Mark | last post by:
Hey everybody. Is there an easy way in vb.net to convert the local time of a machine to US CST ? My machines are distributed throughout and the server is requesting we send the time of the txns...
11
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why...
9
by: Phil B | last post by:
I am having a problem with a datetime from a web services provider The provider is sending the following SOAP response <?xml version="1.0" encoding="utf-8"?> <soap:Envelope...
12
by: conckrish | last post by:
Hi all.. Can anyone tell me how to compare datetime objects?I ve three objects namely Current date,start date and end date.. I need to check the current date with Start date and end date....Plz...
9
by: Abhishek | last post by:
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...
2
by: nightwatch77 | last post by:
Hi, does anyone know why .Net incorrectly handles time zone conversion when passing DateTime through web services? The problem is that it seems to ignore the time zone part. My time zone is CEST,...
2
by: Andy B | last post by:
I have a few questions about xml, DateTime conversions and DateTime fields. 1. in the example of DateTime.Now, how would you save it in the format yyyy-mm-ddThh:mm:ssZ for xml storage? 2. If I...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.