在Perl中获得Epoch毫秒的最佳方式是什么?
问题描述:
很容易获得大纪元秒(时间戳)在Perl:在Perl中获得Epoch毫秒的最佳方式是什么?
time
但是,什么是用毫秒?最有效的方法似乎是时间* 1000,但这并不像我想要的那样准确。除了长期记录的@perldoc之外,还有什么好的提示?
答
的Time::HiRes模块有时间下拉更换
$ perl -E 'say time'
1298827929
$ perl -MTime::HiRes=time -E 'say time'
1298827932.67446
perldoc -q "How can I measure time under a second"
答
一个真实的例子是:
use Time::HiRes qw(gettimeofday);
print gettimeofday;
答
perl -MTime::HiRes=time -e 'print time;'
对于Perl:v5.8.4为构建需要修改SunOS(sun4-solaris-64int),oylenshpeegul's answer。
嗯......我仍然用'Time :: HiRes'得到整数时间。但是,来自该模块的'clock_gettime()'具有诀窍。它是perl 5.10.0 – Dallaylaen 2011-02-27 18:17:30
@Dallaylaen:你是从Time :: HiRes出口时间吗? – ysth 2011-02-27 19:17:20
谢谢,这是我的错误。当然'使用Time :: HiRes qw/time /'很好。 – Dallaylaen 2011-02-27 22:51:56