Ti piace il sito?
Votalo con un clic sul
banner qui sotto ^_^
Calcolare il fuso orario rispetto alla UTC (Greenwich GMT)
Sfruttando qualche funzione dell'API è possibile calcolare, considerando anche l'ora legale, il fuso orario rispetto alla coordinata di tempo universale UTC (Greenwich GMT). Ecco quanto serve ^_^
' ritorna la data e l'ora di sistema
Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
' ritorna la data e l'ora locale
Private Declare Sub GetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
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 TypePrivate Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(0 To 63) As Byte
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(0 To 63) As Byte
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type' ritorna un intero lungo che specifica il fuso orario rispetto a GMTPublic Function GetGMT() As Long
Dim SysTime As SYSTEMTIME
Dim LocTime As SYSTEMTIME
Dim SysDate As Date
Dim LocDate As Date
' ritorna l'ora corrente UTC (Greenwich)GetSystemTime SysTime' ritorna l'ora localeGetLocalTime LocTime' Data e Ora UTC (Greenwich GMT)
SysDate = Format(SysTime.wDay & "-" & _
SysTime.wMonth & "-" & _
SysTime.wYear & " " & _
SysTime.wHour & ":" & _
SysTime.wMinute & ":" & _
SysTime.wSecond, "dd-mm-yyyy h:N:Ss")
' Data e Ora Locale
LocDate = Format(LocTime.wDay & "-" & _
LocTime.wMonth & "-" & _
LocTime.wYear & " " & _
LocTime.wHour & ":" & _
LocTime.wMinute & ":" & _
LocTime.wSecond, "dd-mm-yyyy h:N:Ss")
GetGMT = DateDiff("h", SysDate, LocDate)
End Function
Esempio di utilizzo
Dim GMT As Long
Dim retVal As String
GMT = GetGMT() If GMT > 0 Then
retVal = "GMT+" & GMT
ElseIf GMT < 0 Then
retVal = "GMT -" & GMT
Else
retVal = "GMT " & GMT
End If
MsgBox retVal, , "Fuso orario"