Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for date2utc.vbs

(view source code of date2utc.vbs as plain text)

  1. Option Explicit
  2.  
  3. Dim dtmDate
  4.  
  5. If WScript.Arguments.Named.Count > 0 Then Syntax
  6.  
  7. With WScript.Arguments.Unnamed
  8. 	' Check command line arguments
  9. 	If .Count = 0 Then dtmDate = Now
  10. 	If .Count > 0 Then dtmDate = .Item(0)
  11. 	If .Count > 1 Then dtmDate = dtmDate & " " & .Item(1)
  12. 	If .Count > 2 Then dtmDate = dtmDate & " " & .Item(2)
  13. 	If .Count > 3 Then Syntax
  14. 	On Error Resume Next
  15. 	dtmDate = CDate( dtmDate )
  16. 	If Err Then
  17. 		On Error Goto 0
  18. 		Syntax
  19. 	End If
  20. 	On Error Goto 0
  21. 	If Not IsDate( dtmDate ) Then Syntax
  22. End With
  23.  
  24. ' Calculate and display the result
  25. WScript.Echo DateDiff( "s", "1970-01-01 00:00:00", dtmDate )
  26.  
  27.  
  28. Sub Syntax
  29. 	WScript.Echo vbcrlf _
  30. 	           & "Date2UTC.vbs,  Version 1.00" _
  31. 	           & vbCrLf _
  32. 	           & "Convert any date/time to Unix time (UTC)" _
  33. 	           & vbCrLf & vbCrLf _
  34. 	           & "Usage:  CSCRIPT.EXE  //NoLogo  Date2UTC.vbs  date  [ time ]" _
  35. 	           & vbCrLf & vbCrLf _
  36. 	           & "Where:  ""date""   is the date to convert (default: current date/time)" _
  37. 	           & vbCrLf _
  38. 	           & "        ""time""   is the optional time to convert" _
  39. 	           & vbCrLf & vbCrLf _
  40. 	           & "Notes:  Though often called UTC, Unix time does not take into account leap" _
  41. 	           & vbCrLf _
  42. 	           & "        seconds, while ""official"" UTC does." _
  43. 	           & vbCrLf _
  44. 	           & "        If the specified date is ambiguous, the current user's date" _
  45. 	           & vbCrLf _
  46. 	           & "        and time format is assumed." _
  47. 	           & vbCrLf & vbCrLf _
  48. 	           & "Written by Rob van der Woude" _
  49. 	           & vbCrLf _
  50. 	           & "http://www.robvanderwoude.com"
  51. 	WScript.Quit 1
  52. End Sub
  53.  

page last modified: 2024-04-16; loaded in 0.0052 seconds