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

(编辑:jimmy 日期: 2024/11/9 浏览:2)

例如下面的代码在当前时间返回: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

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

一句话新闻

微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。