神剑山庄资源网 Design By www.hcban.com

VBS显示当前标准时间,例如:执行下面的代码则显示:2013-05-11 19:10:11

Option Explicit
 
Dim blnDate, blnTime
Dim dtmDate
Dim intDay, intFormat, intHour, intMin, intMonth, intSec, intUTC, intValid, intYear
Dim strISO
 
With WScript.Arguments
  ' Check command line arguments
  If .Unnamed.Count = 0 Then dtmDate = Now
  If .Unnamed.Count > 0 Then dtmDate = .Unnamed(0)
  If .Unnamed.Count > 1 Then dtmDate = dtmDate & " " & .Unnamed(1)
  If .Unnamed.Count > 2 Then dtmDate = dtmDate & " " & .Unnamed(2)
  If .Unnamed.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
  intValid = 0
  blnDate = True
  blnTime = True
  If .Named.Exists( "D" ) Then
    blnDate = True
    blnTime = False
    intValid = intValid + 1
  End If
  If .Named.Exists( "T" ) Then
    blnDate = False
    blnTime = True
    intValid = intValid + 1
  End If
  If intValid <> .Named.Count Then Syntax
  If intValid > 1 Then Syntax
End With
 
' Format the output string
intYear = DatePartLZ( "yyyy", dtmDate )
intMonth = DatePartLZ( "m", dtmDate )
intDay  = DatePartLZ( "d", dtmDate )
intHour = DatePartLZ( "h", dtmDate )
intMin  = DatePartLZ( "n", dtmDate )
intSec  = DatePartLZ( "s", dtmDate )
If blnDate Then strISO = intYear & "-" & intMonth & "-" & intDay
If blnTime Then strISO = strISO & " " & intHour & ":" & intMin & ":" & intSec
' Display the result
WScript.Echo Trim( strISO )
 
 
Function DatePartLZ( myInterval, myDate )
  ' Add a leading zero to the DatePart() if necessary
  Dim strDatePart
  strDatePart = DatePart( myInterval, myDate )
  If Len( strDatePart ) < 2 Then strDatePart = "0" & strDatePart
  DatePartLZ = strDatePart
End Function
 
 
Sub Syntax
  WScript.Echo vbcrlf _
        & "Date2ISO.vbs, Version 1.02" _
        & vbCrLf _
        & "Convert any date/time to ISO date/time" _
        & vbCrLf & vbCrLf _
        & "Usage: CSCRIPT.EXE //NoLogo Date2ISO.vbs date [ time ] [ /D | /T ]" _
        & vbCrLf & vbCrLf _
        & "Where: ""date""  is the date to convert (default: current date/time)" _
        & vbCrLf _
        & "    ""time""  is the optional time to convert" _
        & vbCrLf _
        & "    /D    return date only (default: both date and time)" _
        & vbCrLf _
        & "    /T    return time only (/D and /T are mutually exclusive)" _
        & vbCrLf & vbCrLf _
        & "Note:  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校准系统时间 BY BatMan 
Dim objXML, Url, Message 
Message = "恭喜你,本机时间非常准确无需校对!" 
Set objXML = CreateObject("MSXML2.XmlHttp") 
Url = "http://open.baidu.com/special/time/" 
objXML.open "GET", Url, False 
objXML.send() 
Do Until objXML.readyState = 4 : WScript.Sleep 200 : Loop 
Dim objStr, LocalDate 
objStr = objXML.responseText 
LocalDate = Now() 
Set objXML = Nothing 
Dim objREG, regNum 
Set objREG = New RegExp 
objREG.Global = True 
objREG.IgnoreCase = True 
objREG.Pattern = "window.baidu_time\((\d{13,})\)" 
regNum = Int(objREG.Execute(objStr)(0).Submatches(0)) /1000 
Dim OldDate, BJDate, Num, Num1 
OldDate = "1970-01-01 08:00:00" 
BJDate = DateAdd("s", regNum, OldDate) 
Num = DateDiff("s", LocalDate, BJDate) 
If Abs(Num) >=1 Then 
Dim DM, DT, TM, objSHELL 
DM = DateAdd("S", Num, Now()) 
DT = DateValue(DM) 
TM = TimeValue(DM) 
If InStr(Now, "午") Then 
Dim Arr, Arr1, h24 
Arr = Split(TM, " ") 
Arr1 = Split(Arr(1), ":") 
h24 = Arr1(0) 
If Arr(0) = "下午" Then 
h24 = h24 + 12 
Else 
If h24 = 12 Then h24 = 0 
End If 
TM = h24 & ":" & Arr1(1) & ":" & Arr1(2) 
End If 
Set objSHELL = CreateObject("Wscript.Shell") 
objSHELL.Run "cmd /cdate " & DT, False, True 
objSHELL.Run "cmd /ctime " & TM, False, True 
Num1 = Abs(DateDiff("s", Now(), BJDate)) 
Message = "【校准前】" & vbCrLf _ 
& "标准北京时间为:" & vbTab & BJDate & vbCrLf _ 
& "本机系统时间为:" & vbTab & LocalDate & vbCrLf _ 
& "与标准时间相差:" & vbTab & Abs(Num) & "秒" & vbCrLf & vbCrLf _ 
& "【校准后】" & vbCrLf _ 
& "本机系统时间为:" & vbTab & Now() & vbCrLf _ 
& "与标准时间相差:" & vbTab & Num1 & "秒" 
Set objSHELL = Nothing 
End If 
WScript.Echo Message 

以上所述就是本文的全部内容了,希望对大家学习VBS能够有所帮助。

标签:
VBS,当前标准时间

神剑山庄资源网 Design By www.hcban.com
神剑山庄资源网 免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
神剑山庄资源网 Design By www.hcban.com

评论“VBS显示当前标准时间”

暂无VBS显示当前标准时间的评论...

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。