Re: Finding the offset of a specific time zone

John Warner <[email protected]> Wed, 25 Mar 2009 14:18:56 -0400
Newsgroups gmane.comp.windows.devel.dotnet.advanced
Organization House
Message-ID <017f01c9ad76$29b936c0$7d2ba440$@com>
http://tf.nist.gov/service/its.htm

See if this helps. Read through the entire page and note the TT portion of
the data and explanation. It appears to have an answer for you as regards
the US in general observing daylight or standard time. If some counties on
the left coast ever decide to go it alone you will once again have an
issue. 

I would be inclined to have a config/dat file that the user can update
when daylight time is observed.  Provide a small util to adjust the time
or just a plain text file that can be edited with notepad. Some sort of
true false thing would be my thought. Congress every few years likes to
play with this. Shows they are important, so you would need to make some
provision for the US political system...



John Warner


> -----Original Message-----
> From: Discussion of advanced .NET topics. [mailto:ADVANCED-
> [email protected]] On Behalf Of Eddie Lascu
> Sent: Wednesday, March 25, 2009 12:59 PM
> To: [email protected]
> Subject: Re: [ADVANCED-DOTNET] Finding the offset of a specific time
zone
> 
> 
> Peter,
> 
> Everything you said, I already figured it out and it's not helping me.
> 
> Again, a time stamp coming from the field device belongs to a different
time
> zone, so using "ToUniversalTime" will give me the wrong result because
> "ToUniversalTime" assumes the time is local which is not the case. I
> explained that the field devices and the server that runs my application
are
> in different time zones.
> 
> On the other hand, I found a class that mimics what TimeZoneInfo does in
> .NET 3.5. Incidentally, it is also called TimeZoneInfo. You can get it
here:
> 
> http://www.codeproject.com/KB/vb/TimeZoneInfo.aspx
> 
> With that, I can instantiate an object of type TimeZoneInfo for Pacific
Time
> (this would be the only parameter that I need to keep in my
configuration
> file: the name of the time zone where the field devices are located).
Having
> that object (which is built based on available time zone information
from
> the subkeys of the registry's
> HKEY_LOCAL_MACHINE\Software\Microsoft\Windows
> NT\CurrentVersion\Time Zones key), I can ask what is the Current Time
Offset
> and that is the offset I need to add to the values that come from the
field
> devices in order to obtain the correct UTC.
> 
> Thank you everyone for pitching in with your ideas.
> 
> Regards,
> Eddie
> 
> 
> 
> -----Original Message-----
> From: Discussion of advanced .NET topics.
> [mailto:[email protected]] On Behalf Of
> Peter Ritchie
> Sent: Wednesday, March 25, 2009 12:44 PM
> To: [email protected]
> Subject: Re: [ADVANCED-DOTNET] Finding the offset of a specific time
zone
> 
> You can use DateTime.UtcNow to get the current time in UTC.  e.g.:
> DateTime utcDate = DateTime.UtcNow;
> 
> You can use DateTime.ToUniversalTime() to convert a local time to UTC.
> e.g.:
> DateTime date = new DateTime(1968, 11, 05, 12,0,0); DateTime utcDate =
> date.ToUniversalTime();
> 
> You can change the type of a date from local to UTC with the SpecifyKind
> method (i.e. you get a DateTime object from a database; but it's default
> kind is local and its value is actually UTC) e.g:
> DateTime dateTime = GetRecordDateFromDatabase(id); dateTime =
> dateTime.SpecifyKind(DateTimeKind.Utc);
> 
> You can convert a UTC time to local time with DateTime.ToLocalTime.
E.g.:
> DateTime utcDate = GetUtcDateFromSomewhere(); DateTime localDate =
> utcDate
> .ToLocalTime();
> 
> -- Peter
> 
> ===================================
> View archives and manage your subscription(s) at
> http://peach.ease.lsoft.com/archives
> 
> ===================================
> View archives and manage your subscription(s) at
> http://peach.ease.lsoft.com/archives

===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives