20090416143849.156000+480
关于WbemScripting.SWbemDateTime的详细资料:复制代码
- strUTCTime = "20090416143849.156000+480"
- Set objSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
- objSWbemDateTime.Value = strUTCTime
- dtmLocalTime = objSWbemDateTime.GetVarDate(true) '参数为true可以自动转换为本地时区
- wsh.echo dtmLocalTime
复制代码
- 'cscript /nologo test.vbs
- '获取上次关机的日期和时间
- '我知道读取系统事件日志的方法可能显得简单些,此处不再赘述,纯粹为了学习更多知识。
- strValueName = "HKLM\SYSTEM\CurrentControlSet\Control\Windows\ShutdownTime"
- Set objShell = CreateObject("WScript.Shell")
- intArray = objShell.RegRead(strValueName)
- intTerm = intArray(7)*(2^56) + intArray(6)*(2^48) + intArray(5)*(2^40) + intArray(4)*(2^32) + intArray(3)*(2^24) + intArray(2)*(2^16) + intArray(1)*(2^8) + intArray(0)
- intDays = intTerm/(1E7*86400)
- dtmShutdownUTC = CDate(DateSerial(1601, 1, 1) + intDays)
- 'WScript.Echo dtmShutdownUTC
- Set objSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
- objSWbemDateTime.SetVarDate(dtmShutdownUTC)
- dtmShutdownGMT = objSWbemDateTime.GetVarDate(false)
- 'WScript.Echo dtmShutdownGMT
- intBias = DateDiff("h", dtmShutdownGMT, dtmShutdownUTC)
- 'WScript.Echo intBias
- dtmShutdownLocal = DateAdd("h", intBias, dtmShutdownUTC)
- WScript.Echo dtmShutdownLocal
复制代码
- '本地时间转换为UTC
- Set SWDT = CreateObject("WbemScripting.SWbemDateTime")
- SWDT.SetVarDate Now, True
- Wscript.Echo SWDT
- 'UTC转换为本地时间
- aNow = SWDT.GetVarDate(True)
- Wscript.Echo aNow
C:\Test>cscript /nologo test.vbs 20090418032409.000000+480 4/18/2009 3:24:09 AM |
复制代码
- strValueName = "HKLM\SYSTEM\CurrentControlSet\Control\Windows\ShutdownTime"
- Set objShell = CreateObject("WScript.Shell")
- intArray = objShell.RegRead(strValueName)
- intTerm = intArray(7)*(2^56) + intArray(6)*(2^48) + intArray(5)*(2^40) + intArray(4)*(2^32) + intArray(3)*(2^24) + intArray(2)*(2^16) + intArray(1)*(2^8) + intArray(0)
- intDays = intTerm/(1E7*86400)
- dtmShutdownUTC = CDate(DateSerial(1601, 1, 1) + intDays)
- 'WScript.Echo dtmShutdownUTC
- Set SWDT = CreateObject("WbemScripting.SWbemDateTime")
- SWDT.SetVarDate dtmShutdownUTC, True
- SWDT.Value = Left(SWDT,21)&"+000"
- dtmShutdownLocal = SWDT.GetVarDate(True)
- Wscript.Echo dtmShutdownLocal
复制代码
- '参考:
- 'http://www.windowsitpro.com/article/windows-2000/where-do-windows-2000-and-windows-nt-store-time-zone-information-.aspx
- 'http://www.realsoftware.com/listarchives/realbasic-nug/2004-12/msg01260.html
- Option Explicit
- Function GetNetTime(ByVal Url)
- Dim Bias '时间偏移(分钟)
- Dim objHttp,objReg
- Dim DateLine,tmpDate
- Dim GTime,LocalTime
- 'On Error Resume Next
- Set objReg=CreateObject("WScript.Shell")
- '[ActiveTimeBias]:该键值存储当前系统时间相对格林尼治标准时间的偏移(以分钟为单位)
- '[Bias]:该键值存储当前本地时间相对格林尼治标准时间的偏移(以分钟为单位)
- Bias=objReg.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias")
- Set objReg=Nothing
- Set objHttp=CreateObject("MSXML2.XMLHTTP")
- 'Set objHttp=CreateObject("Microsoft.XMLHTTP")
- With objHttp
- .open "HEAD",Url,False
- .send
- DateLine=.getResponseHeader("Date")
- End With
- Set objHttp = Nothing
- DateLine=Left(DateLine,InStr(1,DateLine,"GMT",vbTextCompare)-2)
- 'MsgBox DateLine
- tmpDate=Split(DateLine,",")
- GTime=tmpDate(1)
- LocalTime=DateAdd("n",-CLng(Bias),GTime) '北京时间:GMT+8
- GetNetTime=LocalTime
- End Function
- MsgBox GetNetTime("http://www.microsoft.com")
欢迎光临 批处理之家 (http://bbs.bathome.net/) | Powered by Discuz! 7.2 |