Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timezone issues

Status
Not open for further replies.

jby1

Programmer
Apr 29, 2003
403
0
0
GB
Hi

I have to implement some business logic that switches at 07:00 New Zealand time. This is the case regardless of there the logic is being run, ie NY, London etc. I cannot find any TimeZone classes, and it looks like Microsoft have taken a decision not to support this kind of thing anyway.

All of the date/times on the system are stored as UTC.

Anyone come across this sort of problem, and any suggestions as to how I can reliably get the New Zealand time? At the moment the only idea that springs to mind is to have a reference table of UTC offsets which I would rather avoid if possible.

Thanks
 
You should be able to avail yourself of the underlying Windows API GetTimeZoneInformation() which has all of the information you need to convert from UTC to display times.
 
It is my understanding that GetTimeZoneInformation() can only be used to retrieve details of the current time zone. I need to be able to get details of the New Zealand time irrespective of the time zone of the PC running the application. I realise that it is possible to use SetTimeZoneInformation() to set the PC to a certain time zone before making the GetTimeZoneInformation() call, but for obvious reasons I cannot do this!

It looks like I am going to have to implement some logic to work this out, which is all well so long as the rules don't significantly change at some point.
 
Timezone information is not going to change anytime soon. Daylightsavings could change over time.

To be sure you always have the correct timesone difference with new-zealand you could look for a webservice that has that information.

Try here to start
A less sure method is to change the timezone on the machine to newzealand, calculate the difference with UTC store that and then set it back to it's original timezone and do the calculation again to calculate the difference with the newzealand time.

All this is of course taking into account that the user has setup his timezone correctly.



Christiaan Baes
Belgium

"In a system where you can define a factor as part of a third factor, you need another layer to check the main layer in case the second layer is not the base unit." - jrbarnett
 
Like you said, .NET does not provide timezone offsets. This is because they're subject to change by fickle politicians.

My suggestion is find out the offset for Auckland or Wellington, and store that as a configurable value (you know...just in case...) and use it in your calculations.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
You know that Microsoft has everything in registry.
All TimeZones are under:
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\
It is easy to extract from there!
obislavu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top