Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for iso2utc.vbs

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

  1. Option Explicit
  2.  
  3. With WScript.Arguments
  4. 	Select Case .Unnamed.Count
  5. 		Case 1
  6. 			' Specified date must be in yyyy-mm-dd format
  7. 			If UBound( Split( .Unnamed(0), "-" ) ) <> 2 Then Syntax
  8. 			' Calculate and display the difference in seconds between the specified and the Unix time base date
  9. 			WScript.Echo DateDiff( "s", "1970-01-01 00:00:00", .Unnamed(0) )
  10. 		Case 2
  11. 			' Specified date must be in yyyy-mm-dd format
  12. 			If UBound( Split( .Unnamed(0), "-" ) ) <> 2 Then Syntax
  13. 			' Specified time must be in hh:mm or hh:mm:ss format
  14. 			If UBound( Split( .Unnamed(1), ":" ) ) <  1 Then Syntax
  15. 			If UBound( Split( .Unnamed(1), ":" ) ) >  2 Then Syntax
  16. 			' Calculate and display the difference in seconds between the specified and the Unix time base date
  17. 			WScript.Echo DateDiff( "s", "1970-01-01 00:00:00", .Unnamed(0) & " " & .Unnamed(1) )
  18. 		Case Else
  19. 			Syntax
  20. 	End Select
  21. 	If .Named.Count > 0 Then Syntax
  22. End With
  23.  
  24.  
  25. Sub Syntax
  26. 	WScript.Echo vbCrLf _
  27. 	           & "ISO2UTC.vbs,  Version 1.00" _
  28. 	           & vbCrLf _
  29. 	           & "Convert an ISO date/time to Unix time (UTC)" _
  30. 	           & vbCrLf & vbCrLf _
  31. 	           & "Usage:  CSCRIPT.EXE  //NoLogo  ISO2UTC.vbs  iso_date  [ iso_time ]" _
  32. 	           & vbCrLf & vbCrLf _
  33. 	           & "Where:  ""iso_date""    is the ISO date we want to convert (YYYY-MM-DD format)" _
  34. 	           & vbCrLf _
  35. 	           & "        ""iso_time""    is the optional time component (HH:mm[:ss] format)" _
  36. 	           & vbCrLf & vbCrLf _
  37. 	           & "Note:   Though often called UTC, Unix time does not take into account leap" _
  38. 	           & vbCrLf _
  39. 	           & "        seconds, while ""official"" UTC does." _
  40. 	           & vbCrLf & vbCrLf _
  41. 	           & "Written by Rob van der Woude" _
  42. 	           & vbCrLf _
  43. 	           & "http://www.robvanderwoude.com"
  44. 	WScript.Quit 1
  45. End Sub
  46.  

page last uploaded: 2017-08-21, 14:26