COMMUNITY

Current time in milliseconds ( javascript / cpp)?


(Flashultra) #1

What is the correct way to get time in milliseconds in Haxe ( for javascript / cpp platform) ?
I think Sys.time() * 1000 is more appropriate ( because is more accurate and can be compiled to cpp ) , but Sys.time is not supported for javascritpt ( HTML5) .
From other side Date.now().getTime() will return per-second precision ( depends of target) .
Why Haxe not have one function which can return milliseconds for all targets ?


(Dmitry Hryppa) #2

Try this: https://api.haxe.org/haxe/Timer.html#stamp
It should work on all targets.

haxe.Timer.stamp() returns time in seconds, but with fraction (1531224658.135 for example), so you can multiply it by 1000 and get accurate milliseconds.