Blog Stats
  • Posts - 7
  • Articles - 0
  • Comments - 5
  • Trackbacks - 14

 

Converting Windows time to Unix time, with VBscript

Some command line tools ask for the UNIX time. If you’re using Jscript, this is no a problem. But VBscript doesn’t have a function that does this.

 

So here is some nice one-liner that gives the UNIX time

 

WScript.echo DateDiff("s", "12/31/1969 00:00:00", _
 DateSerial(Year(Now), Month(Now), Day(Now)) _
 + TimeSerial(Hour(Now), Minute(Now), Second(Now)))


Feedback

# re: Converting Windows time to Unix time, with VBscript

Gravatar I was trying to do this in .NET, and although your function is close it wasn't close enough that I could match md5 hashes from a php unix epoch to the .net. The following function worked though:

' Convert a local windows time to UTC and turn it
' into a unix timestamp by diffing it with unix EPOCH
' EPOCH: Private EPOCH As New Date(1970, 1, 1, 0, 0, 0)
Private Function WindowsTimeToUnixTime(ByVal Convert As Date) As Long
Return DateDiff(DateInterval.Second, EPOCH, Convert.ToUniversalTime())
End Function 10/5/2005 12:05 PM | Mike

Post a comment





 

Please add 6 and 8 and type the answer here:

 

 

Copyright © Michel Klomp