There are plenty of times where I need to obtain the current UTC time, in the unix timestamp format.
I’ve written the following helper method that extends the Date object to get the job done easily, and are sharing it here for anyone else who might find it useful.
Function UnixUTCTime(Extends d As Date) As UInt64 Dim tmpUInt64 As UInt64 Dim timeDiff As UInt64 timeDiff = d.GMTOffset * 60 * 60 tmpUInt64 = d.TotalSeconds tmpUInt64 = tmpUInt64 - 2082844800 - timeDiff return tmpUInt64 End Function
Just paste the code in any public module. You use it as follow:
Dim d As New Date() MsgBox Str(d.UnixUTCTime)