How to get the current millisecond level unix time?
Code: Select all
Now := A_Now
EnvSub, Now, 19700101000000, Seconds
Now := Now * 1000 + A_MSec
Code: Select all
Now := A_Now
EnvSub, Now, 19700101000000, Seconds
Now := Now * 1000 + A_MSec
Code: Select all
Time := A_NowUTC
EnvSub, Time, 19700101000000, Seconds
MsgBox, %Time%
Code: Select all
time := A_NowUTC
time -= 1970, s
MsgBox, % time . "000"
This algorithm is very good. But not milliseconds.TheDewd wrote: ↑17 May 2019, 15:58Code: Select all
Time := A_NowUTC EnvSub, Time, 19700101000000, Seconds MsgBox, %Time%
teadrinker wrote: ↑18 May 2019, 07:02Code: Select all
time := A_NowUTC time -= 1970, s MsgBox, % time . "000"
Code: Select all
Now := A_NowUTC
EnvSub, Now, 19700101000000, Seconds
Now := Now * 1000 + A_MSec
Code: Select all
Start := A_TickCount
m := A_MSec
r := A_NowUTC
r -= 19700101000000, s
Elapsed := A_TickCount - Start
msgbox , % r * 1000 + m + Elapsed
Code: Select all
r := A_NowUTC
r -= 19700101000000, s
msgbox , % r * 1000 + A_MSec
Code: Select all
q:: ;test date now Unix
;note: A_MSec is used for testing, but JEE_DateNowUnix("ms") should be more reliable
MsgBox, % JEE_DateNowUnix("s") " " A_MSec "`r`n" JEE_DateNowUnix("ms")
return
JEE_DateNowUnix(vFormat:="")
{
local
;equivalent to code below
;if (vFormat = "") || (vFormat = "s")
; return DateDiff(A_NowUTC, 1970, "Seconds")
vIntervals := 0
DllCall("kernel32\GetSystemTimeAsFileTime", "Int64*",vIntervals)
;note: 116444736000000000 is 1 Jan 1970 UTC as a FILETIME
if (vFormat = "") || (vFormat = "s")
return (vIntervals - 116444736000000000) // 10000000
else if (vFormat = "ms")
return (vIntervals - 116444736000000000) // 10000
return ""
}
Code: Select all
r := A_NowUTC
r -= 19700101000000, s
msgbox , % (r * 1000 + A_MSec) "`n" GetSystemTimeAsUnixTime()
; https://stackoverflow.com/a/46024468
GetSystemTimeAsUnixTime() {
static UNIX_TIME_START := 0x019DB1DED53E8000 ; January 1, 1970 (start of Unix epoch) in "ticks"
, TICKS_PER_SECOND := 10000000 ; A tick is 100ns
DllCall("GetSystemTimeAsFileTime", "Int64*", UTC_Ticks) ; Returns ticks in UTC
Return (UTC_Ticks - UNIX_TIME_START) / TICKS_PER_SECOND
}
Thanks, converted to AutoHotkey V2 version (as I need to modify)TheDewd wrote: ↑17 May 2019, 15:58Code: Select all
Time := A_NowUTC EnvSub, Time, 19700101000000, Seconds MsgBox, %Time%
Code: Select all
Time := A_NowUTC
Time := DateDiff(Time, 19700101000000, "Seconds")
MsgBox(Time)
Code: Select all
A := new biga() ; requires https://github.com/biga-ahk/biga.ahk
A.now()
; => 1636159584000