[Common]
Description=演示如何获取网络时间并与选定的基准时间比较相差天数
HotKeyStart=119
HotKeyStop=122
HotKeyPause=0
Enabled=1
RunOnce=1

[Script]
var t=0
var t0=0
main
  //获取网络时间
  set t=vbscall("GetNetTime")
  do ShowMsg(t)             //显示网络时间
  //设定基准时间
  set t0=vbscall("InitTime","2009-1-1")
  do ShowMsg(t0)            //显示基准时间
  //显示网络时间与基准时间之间相差的天数
  do ShowMsg(Trunc(t-t0))
endmain
vbsbegin
function GetNetTime()
    ' //获取百度原始时间 如:Thu, 08 Jan 2009 04:09:52 GMT
    Set XmlHttp = CreateObject("Microsoft.XMLHTTP")
    XmlHttp.Open "Get", "http://www.baidu.com/", False
    XmlHttp.send
    datetxt=XmlHttp.getResponseHeader("Date")
    Set XmlHttp = Nothing
    '//将获取到的原始时间进行格式化 2009年01月08日 04:09:52
    temdate = Split(datetxt, ",")
    tempvar = Replace(temdate(1), "GMT", "")
    temptim = Split(tempvar, " ")
    Select Case temptim(2)
    Case "Jan":
    mon = "01"
    Case "Feb":
    mon = "02"
    Case "Mar":
    mon = "03"
    Case "Apr":
    mon = "04"
    Case "Mar":
    mon = "05"
    Case "Jun":
    mon = "06"
    Case "Jul":
    mon = "07"
    Case "Aug":
    mon = "08"
    Case "Sep":
    mon = "09"
    Case "Oct":
    mon = "10"
    Case "Nov":
    mon = "11"
    Case "Dec":
    mon = "12"
    End Select
    '//将获取到的时间转换为北京时间+8小时
    timeGMT = CDate(temptim(3) & "年" & mon & "月" & temptim(1) & "日" & temptim(4))
    GetNetTime = DateAdd("h", 8, timeGMT)
End Function
function InitTime(TimeStr)
    InitTime=CDate(TimeStr)
end function
vbsend
