国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > VBScript > 正文

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

2020-06-26 18:31:25
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文給大家分享的是使用vbs來(lái)顯示當(dāng)前時(shí)間的2個(gè)實(shí)例,非常的簡(jiǎn)單實(shí)用,有需要的小伙伴可以參考下。

VBS顯示當(dāng)前標(biāo)準(zhǔn)時(shí)間,例如:執(zhí)行下面的代碼則顯示:2013-05-11 19:10:11

 

 
  1. Option Explicit 
  2.  
  3. Dim blnDate, blnTime 
  4. Dim dtmDate 
  5. Dim intDay, intFormat, intHour, intMin, intMonth, intSec, intUTC, intValid, intYear 
  6. Dim strISO 
  7.  
  8. With WScript.Arguments 
  9. ' Check command line arguments 
  10. If .Unnamed.Count = 0 Then dtmDate = Now 
  11. If .Unnamed.Count > 0 Then dtmDate = .Unnamed(0) 
  12. If .Unnamed.Count > 1 Then dtmDate = dtmDate & " " & .Unnamed(1) 
  13. If .Unnamed.Count > 2 Then dtmDate = dtmDate & " " & .Unnamed(2) 
  14. If .Unnamed.Count > 3 Then Syntax 
  15. On Error Resume Next 
  16. dtmDate = CDate( dtmDate ) 
  17. If Err Then 
  18. On Error Goto 0 
  19. Syntax 
  20. End If 
  21. On Error Goto 0 
  22. If Not IsDate( dtmDate ) Then Syntax 
  23. intValid = 0 
  24. blnDate = True 
  25. blnTime = True 
  26. If .Named.Exists( "D" ) Then 
  27. blnDate = True 
  28. blnTime = False 
  29. intValid = intValid + 1 
  30. End If 
  31. If .Named.Exists( "T" ) Then 
  32. blnDate = False 
  33. blnTime = True 
  34. intValid = intValid + 1 
  35. End If 
  36. If intValid <> .Named.Count Then Syntax 
  37. If intValid > 1 Then Syntax 
  38. End With 
  39.  
  40. ' Format the output string 
  41. intYear = DatePartLZ( "yyyy", dtmDate ) 
  42. intMonth = DatePartLZ( "m", dtmDate ) 
  43. intDay = DatePartLZ( "d", dtmDate ) 
  44. intHour = DatePartLZ( "h", dtmDate ) 
  45. intMin = DatePartLZ( "n", dtmDate ) 
  46. intSec = DatePartLZ( "s", dtmDate ) 
  47. If blnDate Then strISO = intYear & "-" & intMonth & "-" & intDay 
  48. If blnTime Then strISO = strISO & " " & intHour & ":" & intMin & ":" & intSec 
  49. ' Display the result 
  50. WScript.Echo Trim( strISO ) 
  51.  
  52.  
  53. Function DatePartLZ( myInterval, myDate ) 
  54. ' Add a leading zero to the DatePart() if necessary 
  55. Dim strDatePart 
  56. strDatePart = DatePart( myInterval, myDate ) 
  57. If Len( strDatePart ) < 2 Then strDatePart = "0" & strDatePart 
  58. DatePartLZ = strDatePart 
  59. End Function 
  60.  
  61.  
  62. Sub Syntax 
  63. WScript.Echo vbcrlf _ 
  64. "Date2ISO.vbs, Version 1.02" _ 
  65. & vbCrLf _ 
  66. "Convert any date/time to ISO date/time" _ 
  67. & vbCrLf & vbCrLf _ 
  68. "Usage: CSCRIPT.EXE //NoLogo Date2ISO.vbs date [ time ] [ /D | /T ]" _ 
  69. & vbCrLf & vbCrLf _ 
  70. "Where: ""date"" is the date to convert (default: current date/time)" _ 
  71. & vbCrLf _ 
  72. " ""time"" is the optional time to convert" _ 
  73. & vbCrLf _ 
  74. " /D return date only (default: both date and time)" _ 
  75. & vbCrLf _ 
  76. " /T return time only (/D and /T are mutually exclusive)" _ 
  77. & vbCrLf & vbCrLf _ 
  78. "Note: If the specified date is ambiguous, the current user's date" _ 
  79. & vbCrLf _ 
  80. " and time format is assumed." _ 
  81. & vbCrLf & vbCrLf _ 
  82. "Written by Rob van der Woude" _ 
  83. & vbCrLf _ 
  84. "http://www.robvanderwoude.com" 
  85. WScript.Quit 1 
  86. End Sub 

附上一段VBS校對(duì)系統(tǒng)時(shí)間的代碼給大家參考下

 

 
  1. 'VBS校準(zhǔn)系統(tǒng)時(shí)間 BY BatMan  
  2. Dim objXML, Url, Message  
  3. Message = "恭喜你,本機(jī)時(shí)間非常準(zhǔn)確無(wú)需校對(duì)!" 
  4. Set objXML = CreateObject("MSXML2.XmlHttp")  
  5. Url = "http://open.baidu.com/special/time/" 
  6. objXML.open "GET", Url, False 
  7. objXML.send()  
  8. Do Until objXML.readyState = 4 : WScript.Sleep 200 : Loop 
  9. Dim objStr, LocalDate  
  10. objStr = objXML.responseText  
  11. LocalDate = Now()  
  12. Set objXML = Nothing 
  13. Dim objREG, regNum  
  14. Set objREG = New RegExp  
  15. objREG.Global = True 
  16. objREG.IgnoreCase = True 
  17. objREG.Pattern = "window.baidu_time/((/d{13,})/)" 
  18. regNum = Int(objREG.Execute(objStr)(0).Submatches(0)) /1000  
  19. Dim OldDate, BJDate, Num, Num1  
  20. OldDate = "1970-01-01 08:00:00" 
  21. BJDate = DateAdd("s", regNum, OldDate)  
  22. Num = DateDiff("s", LocalDate, BJDate)  
  23. If Abs(Num) >=1 Then 
  24. Dim DM, DT, TM, objSHELL  
  25. DM = DateAdd("S", Num, Now())  
  26. DT = DateValue(DM)  
  27. TM = TimeValue(DM)  
  28. If InStr(Now, "午") Then 
  29. Dim Arr, Arr1, h24  
  30. Arr = Split(TM, " ")  
  31. Arr1 = Split(Arr(1), ":")  
  32. h24 = Arr1(0)  
  33. If Arr(0) = "下午" Then 
  34. h24 = h24 + 12  
  35. Else 
  36. If h24 = 12 Then h24 = 0  
  37. End If 
  38. TM = h24 & ":" & Arr1(1) & ":" & Arr1(2)  
  39. End If 
  40. Set objSHELL = CreateObject("Wscript.Shell")  
  41. objSHELL.Run "cmd /cdate " & DT, False, True 
  42. objSHELL.Run "cmd /ctime " & TM, False, True 
  43. Num1 = Abs(DateDiff("s", Now(), BJDate))  
  44. Message = "【校準(zhǔn)前】" & vbCrLf _  
  45. "標(biāo)準(zhǔn)北京時(shí)間為:" & vbTab & BJDate & vbCrLf _  
  46. "本機(jī)系統(tǒng)時(shí)間為:" & vbTab & LocalDate & vbCrLf _  
  47. "與標(biāo)準(zhǔn)時(shí)間相差:" & vbTab & Abs(Num) & "秒" & vbCrLf & vbCrLf _  
  48. "【校準(zhǔn)后】" & vbCrLf _  
  49. "本機(jī)系統(tǒng)時(shí)間為:" & vbTab & Now() & vbCrLf _  
  50. "與標(biāo)準(zhǔn)時(shí)間相差:" & vbTab & Num1 & "秒" 
  51. Set objSHELL = Nothing 
  52. End If 
  53. WScript.Echo Message  

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

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 拉孜县| 景东| 贺州市| 辽中县| 八宿县| 昂仁县| 上栗县| 黄浦区| 缙云县| 玉门市| 梨树县| 噶尔县| 班戈县| 马公市| 车险| 满城县| 大庆市| 临安市| 聊城市| 郓城县| 仙游县| 休宁县| 汉沽区| 米易县| 尖扎县| 揭西县| 瑞安市| 田阳县| 墨玉县| 长丰县| 福贡县| 桐城市| 南投市| 彰化县| 新津县| 大竹县| 花垣县| 阳原县| 兴宁市| 密山市| 蓬溪县|