calculating the GMT from current time 
Author Message
 calculating the GMT from current time

I am trying to write a program that will give me the GMT time,
regardless of which timezone I am in.  I can calculate the hours if
someone could tell me where I can get timezone info and whether it is
in daylight savingstime or not.

Could anyone tell me how I could go about this?

JoeB



Wed, 18 Jun 1902 08:00:00 GMT  
 calculating the GMT from current time
Hi Joe

Here is the code you should use:

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

Type TIME_ZONE_INFORMATION
        Bias As Long
        StandardName(0 To 32) As Integer
        StandardDate As SYSTEMTIME
        StandardBias As Integer
        DaylightName(0 To 32) As Integer
        DaylightDate As SYSTEMTIME
        DaylightBias As Long
End Type

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

Declare Sub GetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)

Sub GMT()
    Dim udtLocalTime  As SYSTEMTIME
    Dim udtTimeZone As TIME_ZONE_INFORMATION
    Dim dtGMT       As Date
    Dim dtLocal     As Date

    Dim lRetCode    As Long
    Dim nBias       As Integer
    Dim dtBias      As Date

    lRetCode = GetTimeZoneInformation(udtTimeZone)

    nBias = udtTimeZone.Bias / 60

    Call GetLocalTime(udtLocalTime)

    With udtLocalTime
        dtLocal = CDate(.wMonth & "/" & .wDay & "/" & .wYear & _
            " " & .wHour & ":" & .wMinute & ":" & .wSecond)
    End With

    dtBias = CDate(Abs(nBias) & ":00:00")

    If nBias >= 0 Then
        dtGMT = dtLocal + dtBias
    Else
        dtGMT = dtLocal - dtBias
    End If

     MsgBox "LocalTime " & dtLocal & vbCrLf & "GMT " & dtGMT

End Sub

With respect

Alex


Quote:
> I am trying to write a program that will give me the GMT time,
> regardless of which timezone I am in.  I can calculate the hours if
> someone could tell me where I can get timezone info and whether it is
> in daylight savingstime or not.

> Could anyone tell me how I could go about this?

> JoeB

Sent via Deja.com http://www.deja.com/
Before you buy.


Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Formatting Time to GMT when current Time Zone not known

2. how to calculate the GMT (greenwich mean time)

3. Calculate GMT Time with VBScript

4. Help :convert current time to GMT

5. Finding Timezone to Calculate GMT

6. converting PST/PDT time to GMT time

7. How to Convert GMT(Greenwich) Time to short date and time and vice versa

8. Function to return CST time given GMT time?

9. calculate dates calculate time

10. Calculating elapsed time and adding time values

11. GMT to ET and ET to GMT

12. Displaying the Current Date and Current Time

 

 
Powered by phpBB® Forum Software