Yes, I read this, but from the generated code it seems that the idea is to use the Date.now() / 1000 function , but something change this behavior.
Ok, so the only way to get current time should be Date.now().getTime() which created new Date().getTime(); in JS.
In JS Date,now() and new Date().getTime() return same value , but getTime() maybe is twice as slow . Still you can’t access JS function Date.now() from haxe without js untyped
For me this is very strange behavior and for getting current date in miliseconds should be used Date.now().getTime() for JS , Sys.time for cpp, neko and even Timer.stamp() for some targets.
Still it’s a little bit strange behavior of Haxe. At example:
If I want to get miliseconds for JS, eval, Hashlink , i should do something like that:
Using methods available on all platforms var ms = #if js Date.now().getTime(); #else Timer.stamp()*1000; #end
Using target specifics methods var ms = #if js js.lib.Date.now() ; #else Sys.time()*1000; #end
For me it is inconsistent behavior ( (1) available for all platforms ) , and it’s more Haxe implementation rather how language ( JS) works in that case.
You don’t want to use Timer.stamp() to get the current utc time on any platform - that’s not its function, it’s only a coincidence that it gives you this on some platforms and it may change in the future. it’s typically used for measuring time differences when running your program
For getting calendar time, the haxe Date class is what you need to use Date - Haxe 4.2.1 API
For performance measuring, you take two samples with Timer.stamp(), which is performance.now() on js
If you use Date.now().getTime(), you should get millisecond precision on all platforms (excluding neko, which is deprecated). The docs says it’s only second-level precision but reading the source indicates when used this way it’s millisecond precision
There’s a gotcha for some systems where you get second-level precision, but I guess it doesn’t happen very often because it should work for macOS windows and linux
Yes, indeed.
Right now if I want to get milliseconds in Hashlink , I should do : Int64.fromFloat(Sys.time()*1000) , because Sys.time return 5 digits after decimal and Time.stamp() return same ( for Hashlink)