(view source code of utc2iso.vbs as plain text)
Option ExplicitDim blnDate, blnTimeDim dtmBase, dtmUTCDim intDay, intHour, intMin, intMonth, intSec, intUTC, intValid, intYearDim strISOWith WScript.Arguments
' Check command line argumentsIf .Unnamed.Count <> 1 Then Syntax
intUTC = .Unnamed(0)
If Not IsNumeric( intUTC ) 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
dtmBase = "1/1/1970" ' UTC base date
' Calculate the date by adding the Unix time in seconds to the UTC base datedtmUTC = DateAdd( "s", intUTC, dtmBase )
' Format the output stringintYear = DatePartLZ( "yyyy", dtmUTC )
intMonth = DatePartLZ( "m", dtmUTC )
intDay = DatePartLZ( "d", dtmUTC )
intHour = DatePartLZ( "h", dtmUTC )
intMin = DatePartLZ( "n", dtmUTC )
intSec = DatePartLZ( "s", dtmUTC )
If blnDate Then strISO = intYear & "-" & intMonth & "-" & intDay
If blnTime Then strISO = strISO & " " & intHour & ":" & intMin & ":" & intSec
' Display the resultWScript.Echo Trim( strISO )
Function DatePartLZ( myInterval, myDate )
' Add a leading zero to the DatePart() if necessary Dim strDatePartstrDatePart = DatePart( myInterval, myDate )
If Len( strDatePart ) < 2 Then strDatePart = "0" & strDatePart
DatePartLZ = strDatePartEnd Function
Sub SyntaxWScript.Echo vbcrlf _
& "UTC2ISO.vbs, Version 1.01" _
& vbCrLf _& "Convert Unix time (UTC) to ISO date and/or time" _
& vbCrLf & vbCrLf _
& "Usage: CSCRIPT.EXE //NoLogo UTC2ISO.vbs unix_time [ /D | /T ]" _
& vbCrLf & vbCrLf _
& "Where: ""unix_time"" is the Unix time we want to convert" _
& vbCrLf _& " (min: -2147483647, max: 2147483647)" _
& vbCrLf _& " /D return date only (default: both date and time)" _
& vbCrLf _& " /T return time only (/D and /T are mutually exclusive)" _
& vbCrLf & vbCrLf _
& "Note: Though often called UTC, Unix time does not take into account leap" _
& vbCrLf _& " seconds, while ""official"" UTC does." _
& vbCrLf & vbCrLf _
& "Written by Rob van der Woude" _
& vbCrLf _& "http://www.robvanderwoude.com"
WScript.Quit 1
End Sub
page last modified: 2025-10-11; loaded in 0.0087 seconds