脚本专栏 
首页 > 脚本专栏 > 浏览文章

VBS实现将当前时间转换成UTC时间

(编辑:jimmy 日期: 2024/5/16 浏览:3 次 )

例如下面的代码在当前时间返回:1368299689

Option Explicit
 
Dim dtmDate
 
If WScript.Arguments.Named.Count > 0 Then Syntax
 
With WScript.Arguments.Unnamed
  ' Check command line arguments
  If .Count = 0 Then dtmDate = Now
  If .Count > 0 Then dtmDate = .Item(0)
  If .Count > 1 Then dtmDate = dtmDate & " " & .Item(1)
  If .Count > 2 Then dtmDate = dtmDate & " " & .Item(2)
  If .Count > 3 Then Syntax
  On Error Resume Next
  dtmDate = CDate( dtmDate )
  If Err Then
    On Error Goto 0
    Syntax
  End If
  On Error Goto 0
  If Not IsDate( dtmDate ) Then Syntax
End With
 
' Calculate and display the result
WScript.Echo DateDiff( "s", "1970-01-01 00:00:00", dtmDate )
 
 
Sub Syntax
  WScript.Echo vbcrlf _
        & "Date2UTC.vbs, Version 1.00" _
        & vbCrLf _
        & "Convert any date/time to Unix time (UTC)" _
        & vbCrLf & vbCrLf _
        & "Usage: CSCRIPT.EXE //NoLogo Date2UTC.vbs date [ time ]" _
        & vbCrLf & vbCrLf _
        & "Where: ""date""  is the date to convert (default: current date/time)" _
        & vbCrLf _
        & "    ""time""  is the optional time to convert" _
        & vbCrLf & vbCrLf _
        & "Notes: Though often called UTC, Unix time does not take into account leap" _
        & vbCrLf _
        & "    seconds, while ""official"" UTC does." _
        & vbCrLf _
        & "    If the specified date is ambiguous, the current user's date" _
        & vbCrLf _
        & "    and time format is assumed." _
        & vbCrLf & vbCrLf _
        & "Written by Rob van der Woude" _
        & vbCrLf _
        & "http://www.robvanderwoude.com"
  WScript.Quit 1
End Sub

以上所述就是本文的全部内容了,希望大家能够喜欢。

上一篇:VBS显示当前标准时间
下一篇:VBS脚本写的Windows硬件检测工具分享
一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网