Re: Finding the offset of a specific time zone
Eddie Lascu <[email protected]> Wed, 25 Mar 2009 13:31:23 -0400
| Newsgroups | gmane.comp.windows.devel.dotnet.advanced |
|---|---|
| Organization | IBI Group |
| Message-ID | <[email protected]> |
The Web Service that sends me those time stamps could do it, but I am not sure the client is willing to go through that exercise. Rather than wait for them to decide and come up with a cost estimate, a risk factor and the general impact on the overall project, I better take care of business myself. Eddie -----Original Message----- From: Discussion of advanced .NET topics. [mailto:[email protected]] On Behalf Of Michael Levy Sent: Wednesday, March 25, 2009 1:28 PM To: [email protected] Subject: Re: [ADVANCED-DOTNET] Finding the offset of a specific time zone Can the devices be reconfigured to use UTC instead of the local time? -Mike On Wed, Mar 25, 2009 at 12:59 PM, Eddie Lascu <[email protected]> wrote: > > 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 > -- Michael Levy MCPD, MCDBA [email protected] =================================== 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