(view source code of utc2date.vbs as plain text)
Option ExplicitDim blnDate, blnTimeDim dtmBase, dtmUTCDim intDateFormat, intTimeFormat, intUTC, intValidDim strResultWith 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
If .Named.Exists( "T" ) Then Syntax
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 stringIf blnDate Then strResult = FormatDateTime( DateValue( dtmUTC ), intDateFormat )
If blnTime Then
' Calculate and display the difference in seconds between the specified and the Unix time base dateIf blnDate Then strResult = strResult & ", "
strResult = strResult & FormatDateTime( TimeValue( dtmUTC ), intTimeFormat )
End If
WScript.Echo Trim( strResult )
Sub SyntaxWScript.Echo vbcrlf _
& "UTC2Date.vbs, Version 1.00" _
& vbCrLf _& "Convert Unix time (UTC) to the current user's standard date/time format" _
& vbCrLf & vbCrLf _
& "Usage: CSCRIPT.EXE //NoLogo UTC2Date.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.0080 seconds