VBS displays the current standard time

Source: Internet
Author: User
Tags echo message

VBS displays the current standard time

This article will share with you how to use vbs to display the two instances of the current time. It is very simple and practical. For more information, see.

VBS displays the current standard time. For example, the following code is displayed: 19:10:11

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

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

 

'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 _

& Amp; "Date2ISO. vbs, Version 1.02 "_

& VbCrLf _

& "Convert any date/time to ISO date/time "_

& VbCrLf _

& "Usage: CSCRIPT. EXE // NoLogo Date2ISO. vbs date [time] [/D |/T]" _

& 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 _

& "Note: If the specified date is ambiguous, the current user's date "_

& VbCrLf _

& "And time format is assumed ."_

& VbCrLf _

& "Written by Rob van der Woude "_

& VbCrLf _

& "Http://www.robvanderwoude.com"

WScript. Quit 1

End Sub

I have attached a piece of VBS verification system time code for your reference.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

'Vbs calibration system time BY BatMan

Dim objXML, Url, Message

Message = "congratulations, the local time is very accurate and you do not need to proofread it! "

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 = "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, "Wu") Then

Dim Arr, Arr1, h24

Arr = Split (TM ,"")

Arr1 = Split (Arr (1 ),":")

H24 = Arr1 (0)

If Arr (0) = "Afternoon" 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 = "[before calibration]" & vbCrLf _

& "Standard Beijing time:" & vbTab & BJDate & vbCrLf _

& "Local system time:" & vbTab & LocalDate & vbCrLf _

& "Difference from standard time:" & vbTab & Abs (Num) & "second" & vbCrLf _

& "[After calibration]" & vbCrLf _

& "Local system time:" & vbTab & Now () & vbCrLf _

& "Difference from standard time:" & vbTab & Num1 & "seconds"

Set objSHELL = Nothing

End If

WScript. Echo Message

The above is all the content of this article. I hope it will be helpful for you to learn about VBS.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.