Solved

Determining GMT time on my machine?

Posted on 1998-12-16
6
191 Views
Last Modified: 2010-05-03
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
0
Comment
Question by:ljaques
  • 3
  • 3
6 Comments
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
Take a look at the gettimezoneinformation api.
0
 

Author Comment

by:ljaques
Comment Utility
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
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 10 total points
Comment Utility
Here they are:
Private Type TIME_ZONE_INFORMATION
        Bias As Long
        StandardName(1 to 32) As Integer
        StandardDate As SYSTEMTIME
        StandardBias As Long
        DaylightName(1 to 32) As Integer
        DaylightDate As SYSTEMTIME
        DaylightBias As Long
End Type

Private Declare Function GetTimeZoneInformation Lib "kernel32" Alias "GetTimeZoneInformation" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long


0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:ljaques
Comment Utility
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
0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
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.

0
 

Author Comment

by:ljaques
Comment Utility
You are a ****ing lifesaver!!! Thanks very, very much!!!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now