在perl中获取Epoch-Seconds(时间戳)很容易:
time
但毫秒怎么办?最有效的方法似乎是time*1000,但这不够准确。除了@perldoc中记录的长期方案之外,还有什么好的提示吗?
Time::HiRes模块有一个可以替换time函数的工具
$ perl -E 'say time'
1298827929
$ perl -MTime::HiRes=time -E 'say time'
1298827932.67446
您可以在Perl常见问题解答中阅读更多信息。
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гҖӮ - Dallaylaenuse Time::HiRes qw/time/
是可以正常工作的。 - Dallaylaen