• 设为首页
  • 收藏本站
  • 积分充值
  • VIP赞助
  • 手机版
  • 微博
  • 微信
    微信公众号 添加方式:
    1:搜索微信号(888888
    2:扫描左侧二维码
  • 快捷导航
    福建二哥 门户 查看主题

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

    发布者: 涵韵3588 | 发布时间: 2025-8-13 22:43| 查看数: 79| 评论数: 0|帖子模式

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

    2. Dim dtmDate

    3. If WScript.Arguments.Named.Count > 0 Then Syntax

    4. With WScript.Arguments.Unnamed
    5.   ' Check command line arguments
    6.   If .Count = 0 Then dtmDate = Now
    7.   If .Count > 0 Then dtmDate = .Item(0)
    8.   If .Count > 1 Then dtmDate = dtmDate & " " & .Item(1)
    9.   If .Count > 2 Then dtmDate = dtmDate & " " & .Item(2)
    10.   If .Count > 3 Then Syntax
    11.   On Error Resume Next
    12.   dtmDate = CDate( dtmDate )
    13.   If Err Then
    14.     On Error Goto 0
    15.     Syntax
    16.   End If
    17.   On Error Goto 0
    18.   If Not IsDate( dtmDate ) Then Syntax
    19. End With

    20. ' Calculate and display the result
    21. WScript.Echo DateDiff( "s", "1970-01-01 00:00:00", dtmDate )


    22. Sub Syntax
    23.   WScript.Echo vbcrlf _
    24.         & "Date2UTC.vbs, Version 1.00" _
    25.         & vbCrLf _
    26.         & "Convert any date/time to Unix time (UTC)" _
    27.         & vbCrLf & vbCrLf _
    28.         & "Usage: CSCRIPT.EXE //NoLogo Date2UTC.vbs date [ time ]" _
    29.         & vbCrLf & vbCrLf _
    30.         & "Where: ""date""  is the date to convert (default: current date/time)" _
    31.         & vbCrLf _
    32.         & "    ""time""  is the optional time to convert" _
    33.         & vbCrLf & vbCrLf _
    34.         & "Notes: Though often called UTC, Unix time does not take into account leap" _
    35.         & vbCrLf _
    36.         & "    seconds, while ""official"" UTC does." _
    37.         & vbCrLf _
    38.         & "    If the specified date is ambiguous, the current user's date" _
    39.         & vbCrLf _
    40.         & "    and time format is assumed." _
    41.         & vbCrLf & vbCrLf _
    42.         & "Written by Rob van der Woude" _
    43.         & vbCrLf _
    44.         & "http://www.robvanderwoude.com"
    45.   WScript.Quit 1
    46. End Sub
    复制代码
    以上所述就是本文的全部内容了,希望大家能够喜欢。

    来源:互联网
    免责声明:如果侵犯了您的权益,请联系站长(1277306191@qq.com),我们会及时删除侵权内容,谢谢合作!

    最新评论

    浏览过的版块

    QQ Archiver 手机版 小黑屋 福建二哥 ( 闽ICP备2022004717号|闽公网安备35052402000345号 )

    Powered by Discuz! X3.5 © 2001-2023

    快速回复 返回顶部 返回列表