在Perl中获取Epoch毫秒的最佳方法是什么?

时间:2011-02-27 17:08:50

标签: perl timestamp epoch

在perl中很容易获得Epoch-Seconds(时间戳):

time

但是毫秒是多少?最有效的方式似乎是时间* 1000,但这并不像我希望的那样准确。除了长期记录@perldoc以外的任何好的提示?

3 个答案:

答案 0 :(得分:13)

Time::HiRes模块有一个替换时间

$ perl -E 'say time'
1298827929
$ perl -MTime::HiRes=time -E 'say time'
1298827932.67446

你可以read more in the perl FAQ

perldoc -q "How can I measure time under a second"

答案 1 :(得分:4)

现实世界的例子是:

use Time::HiRes qw(gettimeofday);
print gettimeofday;

答案 2 :(得分:0)

perl -MTime::HiRes=time -e 'print time;'

对于为 SunOS (sun4-solaris-64int)构建的 Perl:v5.8.4 ,需要修改oylenshpeegul's answer

相关问题