[英]How to get current time in milliseconds in Haxe?
I need a function that returns the local time in milliseconds on the CPP target.我需要一个函数来返回 CPP 目标上的本地时间(以毫秒为单位)。
I tried Haxe's Date
class, but Date.now()
gives me the time in seconds.我试过 Haxe 的
Date
类,但Date.now()
给了我以秒为单位的时间。
Sys.time() * 1000.0
- http://api.haxe.org/Sys.html#time Sys.time() * 1000.0
- http://api.haxe.org/Sys.html#time
Gives the most precise timestamp value (in seconds)
给出最精确的时间戳值(以秒为单位)
To be clear, I tried this and got millisecond resolution on the cpp target.需要明确的是,我尝试了这个并在 cpp 目标上获得了毫秒分辨率。
Sys
is available on cpp, cs, java, macro, neko, php and python. Sys
可用于 cpp、cs、java、macro、neko、php 和 python。
You could try Date.now().getTime()
, however:您可以尝试
Date.now().getTime()
,但是:
Returns the timestamp of the date.
返回日期的时间戳。 It might only have a per-second precision depending on the platforms .
它可能只有每秒精度,具体取决于平台。
A fast way of getting a timestamp would be to use the haxe.Timer.stamp()
method.获取时间戳的一种快速方法是使用
haxe.Timer.stamp()
方法。
Example :示例:
import haxe.Timer;
var timestamp:Float = Timer.stamp(); // return a timestamp in seconds with fractions
Note that the value itself might differ depending on platforms, only differences between two values make sense.请注意,值本身可能因平台而异,只有两个值之间的差异才有意义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.