Not a Member Yet,
Click here to Register
How do you like the new design?






ID: 173
Viewed: 2300
Added: Apr 29, 2002
Version:
Snippet uploaded by: snippet
Written By: Bob Butler
Demo: Sorry, no demo



User Rated at: 0 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

Get Time Zone Information

Highlight all by clicking in box
<!---Declaration--->
'
' Found on the Net Somewhere - Author : Bob Butler
'
'
'The following code demonstrates how to find the current time zone name
'and GMT offset:

Option Explicit

' 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(1 To 2) As Byte ' VB pads integers
wMonth(1 To 2) As Byte ' so we use bytes
wDayOfWeek(1 To 2) As Byte
wDay(1 To 2) As Byte
wHour(1 To 2) As Byte
wMinute(1 To 2) As Byte
wSecond(1 To 2) As Byte
wMilliseconds(1 To 2) As Byte
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 Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Private Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long

Highlight All
<!---Code--->
Private Sub Form_Load()
Dim x As Long ' scratch
Dim tzi As TIME_ZONE_INFORMATION
Dim dtNow As Date ' current system time
Dim dtGMT As Date ' current GMT time
Dim strName As String ' current tz name
Dim strInfo As String ' scratch

Select Case GetTimeZoneInformation(tzi)
' if not daylight assume standard
Case TIME_ZONE_ID_DAYLIGHT:
strName = tzi.DaylightName ' convert to string
Case Else:
strName = tzi.StandardName
End Select

' name terminates with null

x = InStr(strName, vbNullChar)

If x > 0 Then strName = Left$(strName, x - 1)

dtNow = Now ' get time
dtGMT = DateAdd("n", tzi.bias, dtNow) ' calculate GMT
' build string to display info
strInfo = "Time Zone: " & strName & vbCrLf & _
"Local time: " & Format$(dtNow, "dd-mmm-yyyy hh:mm:ss") & vbCrLf & _
"GMT offset: " & CStr(tzi.bias 60) & " hours, " & _
CStr(tzi.bias Mod 60) & " minutes" & vbCrLf & _
"GMT time: " & Format$(dtGMT, "dd-mmm-yyyy hh:mm:ss") & vbCrLf

MsgBox strInfo

End Sub
;


No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Replying to a Comment...


Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2017 snippetlibrary.com All Rights Reserved. Conditions