Dim n As Date n = "2006-6-13 13:34" Dim b As Date b = DateAdd("h", -8, n)
Private Sub Command1_Click() Debug.Print ChDate(#6/13/2006 1:34:20 PM#, -8) '北京时间是东8区,所以国际时间是我们的前8小时 End Sub Public Function ChDate(Ndate As Date, DiffNo As Integer) As Date ChDate = DateAdd("H", DiffNo, Ndate) End Function
Private Sub Command1_Click() Dim D As Date D = Now() MsgBox Format(D - 8 / 24, "DDD,DD MMM YYYY HH:NN:SS") & " GMT" End Sub
Public Declare Function GetTimeZoneInformation Lib "kernel32" Alias "GetTimeZoneInformation" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As LongPublic Type TIME_ZONE_INFORMATION Bias As Long StandardName(32) As Integer StandardDate As SYSTEMTIME StandardBias As Long DaylightName(32) As Integer DaylightDate As SYSTEMTIME DaylightBias As Long End Type'用法: Dim tmz As TIME_ZONE_INFORMATION Dim UTC As DataTime Call GetTimeZoneInformation(tmz)UTC = Now() + tmz.Bias
n = "2006-6-13 13:34"
Dim b As Date
b = DateAdd("h", -8, n)
Debug.Print ChDate(#6/13/2006 1:34:20 PM#, -8) '北京时间是东8区,所以国际时间是我们的前8小时
End Sub
Public Function ChDate(Ndate As Date, DiffNo As Integer) As Date
ChDate = DateAdd("H", DiffNo, Ndate)
End Function
Dim D As Date
D = Now()
MsgBox Format(D - 8 / 24, "DDD,DD MMM YYYY HH:NN:SS") & " GMT"
End Sub
有方法可以直接把当前机器时区和当前时间结合得出来一个GMT时间吗?
我记得JAVASCRIPT是可以的。
d=new Date()
d=new Date(dV)
第一行是取当前机器的时间,与VB的now相同,第二行是指定日期与 1970 年 1 月 1 日午夜间全球标准时间的毫秒数dV,VB中有相当的DateDiff函数。
Bias As Long
StandardName(32) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(32) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type'用法:
Dim tmz As TIME_ZONE_INFORMATION
Dim UTC As DataTime
Call GetTimeZoneInformation(tmz)UTC = Now() + tmz.Bias