WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Time - Timer and Date Functions
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How to Get Time in Relation to GMT

Keywords:     Greenwich Mean Time GMT

Question:

I have a dire need to get the time zone in the numerical format, ie, Pacific Std Time = -8

I just need the -8 part of it, I looked through the windows reg and cant figure out how to get it, am I missing someting, or is there a DLL call I can make?

Answer:

Time zones are in two places in the registry,
	HKEY_LOCAL_MACHINE\System\CurrentControlSet\control\TimeZoneInformation
is where the set up time zone information is put. It does not have the Greenwich Mean Time relationship.
	HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\TimeZones
Has the GMT relationship in the [Display] item.

To get the GMT relationship number you need to query

	HKEY_LOCAL_MACHINE\System\CurrentControlSet\control\TimeZoneInformation[StandardName]
and do a
	RegQueryKeys (@REGMACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Time Zones") 
and test each item of the list with the first word of the [StandardName] from the first query. If you don't get a match, then you have to test each item with the first TWO words from the first query (eg: one key is "AUS Eastern", and you will not find it by looking for AUS or Eastern, but Eastern points to Eastern US and Can.) (there is 1 case where 3 words are needed)

Once you find the correct key, do a RegQueryValue on its [Display] item, and then parse for the number. The Display item is in the form:

(GMT+hh:mm) description or

(GMT-hh:mm) description

It sounds worse than it is. Since it is all in the registry, it will run quite fast.


Question, RE: GMT and Login Script:

I have a windows 95 script that checks the date on a server file and a workstation file with fileymdhms and does some updating when the files differ. When my workstation settings changed for daylight savings time the script processed when both files never changed. Is this a flaw, or i'm I doing something wrong with the scripting? I ran a trace of both functions and the routine returned strings that were one hour different.

I'm running windows NT on the server.

Upon further testing, I found some strange results. The Winbatch script was running as the workstation logs onto the network. The Windows 95 time change dialog was not answered untill after the script ended. I diplayed the time and date returned from fileymdhms and found the information returned to be exactly one hour different. The server and workstation file were identical when running the script.

I thought the date and time stamp was stored in the file? If the Windows 95 client software was calculating the dates, why would they be one our different? Why wouldn't they both return the same information?

Answer:

Background: In 32 bit Windows the time stored with the file is assumed to be GMT time. The time zone offsets that your computer is set to are used to convert GMT time to local time. If the time zone offsets are incorrect, then you will get incorrect results.

The reason for GMT time is for world-wide networks with people in the US, England, and Japan (for example) referencing a file on some central server. What file time should be displayed to the user? The convention is to display it as the user's local time - and this requires a conversion. If the local time is set incorrectly someplace, or if something in the chain of events that creates the file is not doing it correctly...then times start shifting.

The Greenwich Mean Time (or Universal co-ordinated time) is stored in the file. Then it is converted to local time for display. Depending on when the script ran and when the time change occurred the conversion to local time could have been off 1 hour.


Article ID:   W13869
Filename:   Get Time in Relation to GMT.txt
File Created: 1999:04:15:16:56:56
Last Updated: 1999:04:15:16:56:56