佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > VBS顯示當(dāng)前標(biāo)準(zhǔn)時(shí)間

VBS顯示當(dāng)前標(biāo)準(zhǔn)時(shí)間

熱門標(biāo)簽:智能手機(jī) 網(wǎng)站文章發(fā)布 美圖手機(jī) 鐵路電話系統(tǒng) 銀行業(yè)務(wù) 檢查注冊(cè)表項(xiàng) 服務(wù)器配置 呼叫中心市場(chǎng)需求

VBS顯示當(dāng)前標(biāo)準(zhǔn)時(shí)間,例如:執(zhí)行下面的代碼則顯示: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校對(duì)系統(tǒng)時(shí)間的代碼給大家參考下

'VBS校準(zhǔn)系統(tǒng)時(shí)間 BY BatMan 
Dim objXML, Url, Message 
Message = "恭喜你,本機(jī)時(shí)間非常準(zhǔn)確無(wú)需校對(duì)!" 
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 = "【校準(zhǔn)前】"  vbCrLf _ 
 "標(biāo)準(zhǔn)北京時(shí)間為:"  vbTab  BJDate  vbCrLf _ 
 "本機(jī)系統(tǒng)時(shí)間為:"  vbTab  LocalDate  vbCrLf _ 
 "與標(biāo)準(zhǔn)時(shí)間相差:"  vbTab  Abs(Num)  "秒"  vbCrLf  vbCrLf _ 
 "【校準(zhǔn)后】"  vbCrLf _ 
 "本機(jī)系統(tǒng)時(shí)間為:"  vbTab  Now()  vbCrLf _ 
 "與標(biāo)準(zhǔn)時(shí)間相差:"  vbTab  Num1  "秒" 
Set objSHELL = Nothing 
End If 
WScript.Echo Message 

以上所述就是本文的全部?jī)?nèi)容了,希望對(duì)大家學(xué)習(xí)VBS能夠有所幫助。

您可能感興趣的文章:
  • 用vbscript實(shí)現(xiàn)修改屏幕保護(hù)的等待時(shí)間長(zhǎng)度
  • 將WMI中的DateTime類型轉(zhuǎn)換成VBS時(shí)間的函數(shù)代碼
  • 用VBS修改(設(shè)置)系統(tǒng)時(shí)間和日期的代碼
  • 校準(zhǔn)系統(tǒng)時(shí)間的VBS代碼
  • VBS中獲取系統(tǒng)本次及上次開(kāi)關(guān)機(jī)時(shí)間的代碼(WinXP/win2003/Win7兼容版)
  • vbscript實(shí)現(xiàn)的根據(jù)不同時(shí)間段顯示不同的歡迎語(yǔ)
  • vbs獲取當(dāng)前時(shí)間日期的代碼
  • vbscript獲取文件的創(chuàng)建時(shí)間、最后修改時(shí)間和最后訪問(wèn)時(shí)間的方法
  • VBS實(shí)現(xiàn)將當(dāng)前時(shí)間轉(zhuǎn)換成UTC時(shí)間

標(biāo)簽:樂(lè)山 上海 沈陽(yáng) 滄州 長(zhǎng)治 紅河 新疆 河南

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《VBS顯示當(dāng)前標(biāo)準(zhǔn)時(shí)間》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    资源县| 襄汾县| 大理市| 普兰店市| 新昌县| 嵊州市| 东城区| 长白| 京山县| 泰来县| 汉沽区| 新龙县| 广德县| 马边| 漳浦县| 泊头市| 淮阳县| 星座| 尉氏县| 峨眉山市| 资溪县| 德格县| 巧家县| 新龙县| 西吉县| 察隅县| 岳阳县| 光泽县| 贵阳市| 上思县| 新蔡县| 启东市| 九寨沟县| 柳江县| 湛江市| 鄂尔多斯市| 格尔木市| 九龙县| 搜索| 乾安县| 平和县|