• Welcome to Valhalla Legends Archive.
 

time zones

Started by OcTaViuS, May 23, 2003, 10:09 PM

Previous topic - Next topic

OcTaViuS

i was wonderin if it was possible to get the time zone a computer is set for, using VB.

im looking for a way to display date time and timezone. i got the date and time part down, and was wondering how i would go about getting the timezone.

any ideas?

Skywing

Quote from: OcTaViuS on May 23, 2003, 10:09 PM
i was wonderin if it was possible to get the time zone a computer is set for, using VB.

im looking for a way to display date time and timezone. i got the date and time part down, and was wondering how i would go about getting the timezone.

any ideas?

From MSDN:
QuoteGetTimeZoneInformation
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 // time zone
);
Parameters
lpTimeZoneInformation
[out] 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/2000/XP: This value is returned if daylight saving 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/98/Me: This value is returned if daylight saving 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.

Requirements
 Windows NT/2000/XP: Included in Windows NT 3.1 and later.
 Windows 95/98/Me: Included in Windows 95 and later.
 Header: Declared in Winbase.h; include Windows.h.
 Library: Use Kernel32.lib.
And...:
QuoteTIME_ZONE_INFORMATION
The TIME_ZONE_INFORMATION structure specifies information specific to the time zone.

typedef struct _TIME_ZONE_INFORMATION {
   LONG       Bias;
   WCHAR      StandardName[ 32 ];
   SYSTEMTIME StandardDate;
   LONG       StandardBias;
   WCHAR      DaylightName[ 32 ];
   SYSTEMTIME DaylightDate;
   LONG       DaylightBias;
} TIME_ZONE_INFORMATION, *PTIME_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 member could contain "EST" to indicate Eastern Standard Time. This string is not used by the operating system, so anything stored there 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 saving 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.
To select the correct day in the month, set the wYear member to zero, the wDayOfWeek member to an appropriate weekday, and the wDay member to a value in the range 1 through 5. 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 saving time on this operating system. For example, this member 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 saving 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.
To select the correct day in the month, set the wYear member to zero, the wDayOfWeek member to an appropriate weekday, and the wDay member to a value in the range 1 through 5. Using this notation, the first Sunday in April can be specified, as can the last Thursday in October (5 is equal to "the last").

DaylightBias
Specifies a bias value to be used during local time translations that occur during daylight saving 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 saving time. In most time zones, the value of this member is – 60.

Requirements
 Windows NT/2000/XP: Included in Windows NT 3.1 and later.
 Windows 95/98/Me: Included in Windows 95 and later.
 Header: Declared in Winbase.h; include Windows.h.

You should be able to declare these in Visual Basic with the information provided by the "API Viewer".