Solved

Determining GMT time on my machine?

Posted on 1998-12-16
6
192 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
ID: 1450851
Take a look at the gettimezoneinformation api.
0
 

Author Comment

by:ljaques
ID: 1450852
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
ID: 1450853
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:ljaques
ID: 1450854
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
ID: 1450855
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
ID: 1450856
You are a ****ing lifesaver!!! Thanks very, very much!!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

867 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

16 Experts available now in Live!

Get 1:1 Help Now