Link to home
Start Free TrialLog in
Avatar of ljaques
ljaques

asked on

Determining GMT time on my machine?

Is there a way to determine current GMT time on my machine? Before all of you quickly point out that i should just check the Time Zone Tab (under the Date/Time Properties)  and just "+" or "-" my GMT position from my current time...I want to be able to upload my app and have it understand its current GMT time no matter where it was around the world without having the user manually type in the GMT offset "+"/"-" value.

Thanks
Avatar of Mirkwood
Mirkwood

Take a look at the gettimezoneinformation api.
Avatar of ljaques

ASKER

Hi Mirkwood,
  Actually i couldn't find the api anywhere in vb5...Is there a special external call that i must do?  Could you provide the coding to access this api. I will give you the points for it
ASKER CERTIFIED SOLUTION
Avatar of Mirkwood
Mirkwood

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ljaques

ASKER

Hi Mirkwood,
  Thanks for the reply...I was playing with it and i couldn't figfure out what it was returning.

The "STANDARDTIME" constant you mention wasn't found in vb so i switched it to a "Variant" type. When in typed:

dim zone as TIME_ZONE_INFORMATION
GetTimeZoneInformation(zone)

"zone.bias" equaled "600"
"zone.DaylightBias equaled "-30"

and the other zone members didn't equal anything.

What does the information mean and how am i able to tell which zone i am in?

Thanks
Here is the missing info.


Private Type SYSTEMTIME
        wYear As Integer
        wMonth As Integer
        wDayOfWeek As Integer
        wDay As Integer
        wHour As Integer
        wMinute As Integer
        wSecond As Integer
        wMilliseconds As Integer
End Type


The GetTimeZoneInformation function retrieves the current time-zone parameters. These parameters control the translations between Coordinated Universal Time (UTC) and local time.

DWORD GetTimeZoneInformation(
  LPTIME_ZONE_INFORMATION lpTimeZoneInformation   // address of
                                                  // time-zone settings
);
 
Parameters
lpTimeZoneInformation
Pointer to a TIME_ZONE_INFORMATION structure to receive the current time-zone parameters.
Return Values
If the function succeeds, the return value is one of the following values:

Value Meaning
TIME_ZONE_ID_UNKNOWN The system cannot determine the current time zone. This error is also returned if you call the SetTimeZoneInformation function and supply the bias values but no transition dates.
Windows NT: This value is returned if daylight savings time is not used in the current time zone, because there are no transition dates.
 
TIME_ZONE_ID_STANDARD The system is operating in the range covered by the StandardDate member of the TIME_ZONE_INFORMATION structure.
Windows 95: This value is returned if daylight savings time is not used in the current time zone, because there are no transition dates.
 
TIME_ZONE_ID_DAYLIGHT The system is operating in the range covered by the DaylightDate member of the TIME_ZONE_INFORMATION structure.


If the function fails, the return value is TIME_ZONE_ID_INVALID. To get extended error information, call GetLastError.

Remarks
All translations between UTC time and local time are based on the following formula:


UTC = local time + bias
 
The bias is the difference, in minutes, between UTC time and local time.

Windows CE: The GetTimeZoneInformation function always returns TIME_ZONE_ID_UNKNOWN.

QuickInfo

TIME_ZONE_INFORMATION
The TIME_ZONE_INFORMATION structure specifies information specific to the time zone.

typedef struct _TIME_ZONE_INFORMATION { // tzi
    LONG       Bias;
    WCHAR      StandardName[ 32 ];
    SYSTEMTIME StandardDate;
    LONG       StandardBias;
    WCHAR      DaylightName[ 32 ];
    SYSTEMTIME DaylightDate;
    LONG       DaylightBias;
} TIME_ZONE_INFORMATION;
 
Members
Bias
Specifies the current bias, in minutes, for local time translation on this computer. The bias is the difference, in minutes, between Coordinated Universal Time (UTC) and local time. All translations between UTC and local time are based on the following formula:

UTC = local time + bias
 
This member is required.

StandardName
Specifies a null-terminated string associated with standard time on this operating system. For example, this parameter could contain "EST" to indicate Eastern Standard Time. This string is not used by the operating system, so anything stored there by using the SetTimeZoneInformation function is returned unchanged by the GetTimeZoneInformation function. This string can be empty.
StandardDate
Specifies a SYSTEMTIME structure that contains a date and local time when the transition from daylight time to standard time occurs on this operating system. If this date is not specified, the wMonth member in the SYSTEMTIME structure must be zero. If this date is specified, the DaylightDate value in the TIME_ZONE_INFORMATION structure must also be specified.
This member supports two date formats. Absolute format specifies an exact date and time when standard time begins. In this form, the wYear, wMonth, wDay, wHour, wMinute, wSecond, and wMilliseconds members of the SYSTEMTIME structure are used to specify an exact date.

Day-in-month format is specified by setting the wYear member to zero, setting the wDayOfWeek member to an appropriate weekday, and using a wDay value in the range 1 through 5 to select the correct day in the month. Using this notation, the first Sunday in April can be specified, as can the last Thursday in October (5 is equal to "the last").

StandardBias
Specifies a bias value to be used during local time translations that occur during standard time. This member is ignored if a value for the StandardDate member is not supplied.
This value is added to the value of the Bias member to form the bias used during standard time. In most time zones, the value of this member is zero.

DaylightName
Specifies a null-terminated string associated with daylight time on this operating system. For example, this parameter could contain "PDT" to indicate Pacific Daylight Time. This string is not used by the operating system, so anything stored there by using the SetTimeZoneInformation function is returned unchanged by the GetTimeZoneInformation function. This string can be empty.
DaylightDate
Specifies a SYSTEMTIME structure that contains a date and local time when the transition from standard time to daylight time occurs on this operating system. If this date is not specified, the wMonth member in the SYSTEMTIME structure must be zero. If this date is specified, the StandardDate value in the TIME_ZONE_INFORMATION structure must also be specified. This member supports the absolute and day-in-month time formats described for the StandardDate member.
DaylightBias
Specifies a bias value to be used during local time translations that occur during daylight time. This member is ignored if a value for the DaylightDate member is not supplied.
This value is added to the value of the Bias member to form the bias used during daylight time. In most time zones, the value of this member is  60.

Avatar of ljaques

ASKER

You are a ****ing lifesaver!!! Thanks very, very much!!!