First, GMT is these days called UTC.
Then, the function below, DateUtc, returns the UTC time.
Finally, use UnixTimeValue to return your Unix time.
/gustav
' Declarations.
Private Const TIME_ZONE_ID_UNKNOWN As Long = 0
Private Const TIME_ZONE_ID_STANDARD As Long = 1
Private Const TIME_ZONE_ID_DAYLIGHT As Long = 2
Private Const TIME_ZONE_ID_INVALID As Long = &HFFFFFFFF
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 * 2) - 1)) As Byte ' Unicode.
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(0 To ((32 * 2) - 1)) As Byte ' Unicode.
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
' TIME_ZONE_INFORMATION-type variables hold information about the system's selected time zone.
' The two arrays in the structure are actually strings, each element holding the ASCII codes for
' each character (the end of the string is marked by a NULL character, ASCII code 0).
' For more information about how to convert the arrays into usable data, see the example for
' GetTimeZoneInformation.
'
' Bias
' The difference in minutes between UTC (a.k.a. GMT) time and local time.
' It satisfies the formula UTC time = local time + Bias.
'
' StandardName(0 To 31)
' Holds the name of the time zone for standard time.
'
' StandardDate
' The relative date for when daylight savings time ends.
'
' StandardBias
' A number to add to Bias to form the true bias during standard time.
'
' DaylightName(0 To 31)
' Holds the name of the time zone for daylight savings time.
'
' DaylightDate
' The relative date for when daylight savings time begins.
'
' DaylightBias
' A number to add to Bias to form the true bias during daylight savings time.
Private Declare Function GetTimeZoneInformation Lib "Kernel32.dll" ( _
lpTimeZoneInformation As TIME_ZONE_INFORMATION) _
As Long
Public Function DateUtc( _
ByVal datDateLocal As Date) _
As Date
' Returns time datDateLocal converted to UTC time.
Const clngBiasUtc As Long = 0
Dim datUtc As Date
Dim lngBiasLocal As Long
lngBiasLocal = GetLocalTimeZoneBias()
datUtc = DateAddTimeZoneDiff(datDateLocal, lngBiasLocal, clngBiasUtc)
DateUtc = datUtc
End Function
Public Function GetLocalTimeZoneBias( _
Optional ByVal booIgnoreDaylightSetting As Boolean) _
As Long
Dim tzi As TIME_ZONE_INFORMATION
Dim lngTimeZoneID As Long
Dim lngBias As Long
lngTimeZoneID = GetTimeZoneInformation(tzi)
Select Case lngTimeZoneID
Case TIME_ZONE_ID_STANDARD, TIME_ZONE_ID_DAYLIGHT
lngBias = tzi.Bias
If lngTimeZoneID = TIME_ZONE_ID_DAYLIGHT Then
If booIgnoreDaylightSetting = False Then
lngBias = lngBias + tzi.DaylightBias
End If
End If
End Select
GetLocalTimeZoneBias = lngBias
End Function
Public Function DateAddTimeZoneDiff( _
ByVal datLocal As Date, _
ByVal lngLocalBias, _
ByVal lngRemoteBias) _
As Date
' Calculates the date/time of datLocal in a remote time zone.
' Adds the difference in minutes between the local time zone bias and
' the remote time zone bias, if both bias are relative to UTC.
'
' Examples:
'
' datRemote = DateAddTimeZoneDiff(Now(), 60, -600)
' will return datRemote as eleven hours ahead of local time.
'
' datRemote = DateAddTimeZoneDiff(Now(), -600, 60)
' will return datRemote as eleven hours behind local time.
'
' 2000-05-30. Cactus Data ApS, CPH.
' 2005-01-25. Adjusted to accommodate change in TimeZoneBiasDiff().
Dim datRemote As Date
Dim lngBias As Long
' Get difference (in minutes) in time zone bias.
lngBias = TimeZoneBiasDiff(lngLocalBias, lngRemoteBias)
' Calculate remote date/time.
datRemote = DateAdd("n", lngBias, datLocal)
DateAddTimeZoneDiff = datRemote
End Function
Public Function TimeZoneBiasDiff( _
ByVal lngLocalTimeBias As Long, _
ByVal lngRemoteTimeBias As Long) _
As Long
' Calculates the difference in minutes between two time zones,
' typically from the local time zone to the remote time zone.
' Both time zones must be expressed by their bias relative to
' UTC (Coordinated Universal Time) which is measured in minutes.
'
' 2000-05-30. Cactus Data ApS, CPH.
' 2005-01-25. Output reversed to express bias value.
' Minimum amount of minutes for a time zone bias.
Const clngTimeZoneBiasMin As Long = 15
Dim lngTimeZoneBiasDiff As Long
' Round off time zone bias by minimum time zone difference.
lngLocalTimeBias = lngLocalTimeBias \ clngTimeZoneBiasMin
lngLocalTimeBias = lngLocalTimeBias * clngTimeZoneBiasMin
lngRemoteTimeBias = lngRemoteTimeBias \ clngTimeZoneBiasMin
lngRemoteTimeBias = lngRemoteTimeBias * clngTimeZoneBiasMin
' Calculate difference in time zone bias.
lngTimeZoneBiasDiff = lngLocalTimeBias - lngRemoteTimeBias
TimeZoneBiasDiff = lngTimeZoneBiasDiff
End Function
Public Function UnixTimeValue( _
ByVal datTime As Date, _
Optional ByVal lngLocalTimeBias As Long) _
As Double
' Converts UTC date Value to UNIX (or POSIX) time Value.
' Optionally, a local time bias can be specified;
' this must be in minutes with a resolution of 15 minutes.
'
' Examples:
' UTC. datTime: #09/09/2001 01:46:40#, lngLocalTimeBias: 0
' 1000000000
' CET. datTime: #09/09/2001 02:46:40#, lngLocalTimeBias: -60
' 1000000000
'
' 2004-03-23. Cactus Data ApS. CPH.
' 2008-02-27. Constants renamed for clarity.
' UNIX epoch (start time).
Const cdatUnixEpoch As Date = #1/1/1970#
' Maximum time bias in seconds, 12 hours.
Const clngSecondsBiasMax As Long = 12& * 60&
Dim dblSeconds As Double
If lngLocalTimeBias <> 0 Then
If Abs(lngLocalTimeBias) < clngSecondsBiasMax Then
datTime = DateAdd("n", lngLocalTimeBias, datTime)
End If
End If
dblSeconds = DateDiff("s", cdatUnixEpoch, datTime)
UnixTimeValue = dblSeconds
End Function
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202:





by: lucas911Posted on 2009-08-11 at 08:04:19ID: 25069874
Take a look at this:
cel/TimeZo neAndDayli ghtTime.as px
http://www.cpearson.com/ex