Here is a way. It was actually quite complicated. Perhaps someone has a
better way.
Create a new form. But a button in it whose name is cmdGetTimeZone. Then
paste in all of the ode below.
Rdub
' ***** Code Starts *****
Option Compare Database
Option Explicit
' API to access VB6 String by pointer in order to copy memory
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
' API Stuff to Get the Time Zone Info
Private Declare Function GetTimeZoneInformation Lib "kernel32" _
(lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
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
StandardName As String * 64
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName As String * 64
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
Function ToUTF8(ByVal UTF16 As Long) As Byte()
' Convert a 16bit UTF-16BE to 2 or 3 UTF-8 bytes
Dim BArray() As Byte
If UTF16 < &H80 Then
ReDim BArray(0) ' one byte UTF-8
BArray(0) = UTF16 ' Use number as is
ElseIf UTF16 < &H800 Then
ReDim BArray(1) ' two byte UTF-8
BArray(1) = &H80 + (UTF16 And &H3F) ' Least Significant 6 bits
UTF16 = UTF16 \ &H40 ' Shift UTF16 number right 6 bits
BArray(0) = &HC0 + (UTF16 And &H1F) ' Use 5 remaining bits
Else
ReDim BArray(2) ' three byte UTF-8
BArray(2) = &H80 + (UTF16 And &H3F) ' Least Significant 6 bits
UTF16 = UTF16 \ &H40 ' Shift UTF16 number right 6 bits
BArray(1) = &H80 + (UTF16 And &H3F) ' Use next 6 bits
UTF16 = UTF16 \ &H40 ' Shift UTF16 number right 6 bits again
BArray(0) = &HE0 + (UTF16 And &HF) ' Use 4 remaining bits
End If
ToUTF8 = BArray ' Return UTF-8 bytes in an array
End Function
Function UniStrToUTF8(UniString) As Byte()
' Convert a Unicode string to a byte stream of UTF-8
Dim BArray() As Byte
Dim TempB() As Byte
Dim i As Long
Dim k As Long
Dim TLen As Long
Dim b1 As Byte
Dim b2 As Byte
Dim UTF16 As Long
Dim j
TLen = Len(UniString) ' Obtain length of Unicode input string
If TLen = 0 Then Exit Function ' get out if there's nothing to convert
k = 0
For i = 1 To TLen
' Work out the UTF16 value of the Unicode character
CopyMemory b1, ByVal StrPtr(UniString) + ((i - 1) * 2), 1
CopyMemory b2, ByVal StrPtr(UniString) + ((i - 1) * 2) + 1, 1
' Combine the 2 bytes into the Unicode UTF-16
UTF16 = b2 ' assign b2 to UTF16 before multiplying by 256 to avoid
overflow
UTF16 = UTF16 * 256 + b1
' Convert UTF-16 to 2 or 3 bytes of UTF-8
TempB = ToUTF8(UTF16)
' Copy the resultant bytes to BArray
For j = 0 To UBound(TempB)
ReDim Preserve BArray(k)
BArray(k) = TempB(j): k = k + 1
Next
ReDim TempB(0)
Next
UniStrToUTF8 = BArray ' Return the resultant UTF-8 byte array
End Function
Private Sub cmdGetTimeZone_Click()
Dim intStandardMonth As Integer, intStandardDay As Integer
Dim intDaylightMonth As Integer, intDaylightDay As Integer
Dim intMonthNow As Integer, intDayNow As Integer
Dim blnDaylightSavings As Boolean
Dim TZI As TIME_ZONE_INFORMATION
Call GetTimeZoneInformation(TZI)
' Determine if we need to account for daylight savings time.
' this is precise to the day, not to the hour, so if you need
' more precision, change this code to consider wHour, wMinute
' and even wSecond Parameter
intStandardMonth = TZI.StandardDate.wMonth
intStandardDay = TZI.StandardDate.wDay
intDaylightMonth = TZI.DaylightDate.wMonth
intDaylightDay = TZI.DaylightDate.wDay
intMonthNow = Month(Now)
intDayNow = Day(Now)
If intStandardMonth = intMonthNow Then
blnDaylightSavings = (intDayNow < intStandardDay)
ElseIf intDaylightMonth = intMonthNow Then
blnDaylightSavings = (intDayNow >= intDaylightDay)
Else
If intDaylightMonth < intStandardMonth Then
blnDaylightSavings = intMonthNow > intDaylightMonth _
And intMonthNow < intStandardMonth
Else
blnDaylightSavings = intMonthNow > intDaylightMonth _
Or intMonthNow < intStandardMonth
End If
End If
' Now print the Current Zime zone info
If blnDaylightSavings Then
Debug.Print UniStrToUTF8(TZI.DaylightName)
Else
Debug.Print UniStrToUTF8(TZI.StandardName)
End If
End Sub
'***** Code Ends *****