dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Timezone info...

  1. #1
    Alex Kennedy Guest

    Timezone info...



    Anyone know how to find out what the difference between current time (including
    daylight saving) and GMT is? I've tried using GetTimeZoneInformation API
    call it doesn't appear to return anything useful!

    Alex



  2. #2
    Luther Miller Guest

    Re: Timezone info...

    do a search in the archives - there was an article I think in late 99 with a
    sample program. you'll need to update it to work with windows 2000 registry
    settings. In the registry there is a field called TZI - you need to capture
    that data. It tells you how to figure out when DST time starts and ends for
    a given time zone, and how many minutes from UTS the timezone is for DST and
    non-DST...

    "Alex Kennedy" <alex@isistool.co.uk> wrote in message
    news:3ad476f7@news.devx.com...
    >
    >
    > Anyone know how to find out what the difference between current time

    (including
    > daylight saving) and GMT is? I've tried using GetTimeZoneInformation API
    > call it doesn't appear to return anything useful!
    >
    > Alex
    >
    >




  3. #3
    Bob Butler Guest

    Re: Timezone info...

    > "Alex Kennedy" <alex@isistool.co.uk> wrote in message
    > news:3ad476f7@news.devx.com...
    > >
    > >
    > > Anyone know how to find out what the difference between current time

    > (including
    > > daylight saving) and GMT is? I've tried using GetTimeZoneInformation

    API
    > > call it doesn't appear to return anything useful!


    GetTimeZoneInformation returns a lot of good info...

    ' Time Zone API declarations
    Private Const TIME_ZONE_ID_UNKNOWN = 0
    Private Const TIME_ZONE_ID_STANDARD = 1
    Private Const TIME_ZONE_ID_INVALID = &HFFFFFFFF
    Private Const TIME_ZONE_ID_DAYLIGHT = 2
    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
    Private Type TIME_ZONE_INFORMATION
    bias As Long ' current offset to GMT
    StandardName(1 To 64) As Byte ' unicode string
    StandardDate As SYSTEMTIME
    StandardBias As Long
    DaylightName(1 To 64) As Byte
    DaylightDate As SYSTEMTIME
    DaylightBias As Long
    End Type
    Private Declare Function GetTimeZoneInformation Lib "kernel32" _
    (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long

    Private Sub Form_Load()
    Dim x As Long ' scratch
    Dim uTZI As TIME_ZONE_INFORMATION
    Dim dtNow As Date ' current system time
    Dim dtGMT As Date ' current GMT time
    Dim lBias As Long ' current offset
    Dim sName As String ' current tz name
    Dim sDS As String ' Daylight Savings?
    Dim sInfo As String ' scratch
    Select Case GetTimeZoneInformation(uTZI)
    ' if not daylight assume standard
    Case TIME_ZONE_ID_DAYLIGHT:
    sName = uTZI.DaylightName ' convert to string
    lBias = uTZI.bias + uTZI.DaylightBias
    sDS = "Daylight Savings Time is in effect"
    Case Else:
    sName = uTZI.StandardName
    lBias = uTZI.bias + uTZI.StandardBias
    sDS = "Daylight Savings Time is not in effect"
    End Select
    ' name terminates with null
    x = InStr(sName, vbNullChar)
    If x > 0 Then sName = Left$(sName, x - 1)
    dtNow = Now ' get time
    dtGMT = DateAdd("n", lBias, dtNow) ' calculate GMT
    ' build string to display info
    sInfo = "Time Zone: " & sName & vbCrLf & _
    "Local time: " & Format$(dtNow, "dd-mmm-yyyy hh:mm:ss") & _
    vbCrLf & "GMT offset: " & CStr(lBias \ 60) & " hours, " & _
    CStr(lBias Mod 60) & " minutes" & vbCrLf & _
    sDS & vbCrLf & "GMT time: " & _
    Format$(dtGMT, "dd-mmm-yyyy hh:mm:ss") & vbCrLf
    MsgBox sInfo, vbOKOnly, "Time Zone Info"
    Unload Me
    End Sub




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center