【问题标题】:What's the best way to get Epoch milliseconds in Perl?在 Perl 中获得 Epoch 毫秒的最佳方法是什么?
【发布时间】:2011-07-05 07:26:01
【问题描述】:

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

time

但是毫秒是什么?最有效的方法似乎是 time*1000,但这并不像我想要的那样准确。除了长期记录的@perldoc 之外还有什么好的提示吗?

【问题讨论】:

    标签: perl timestamp epoch


    【解决方案1】:

    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"
    

    【讨论】:

    • 嗯...我仍然可以使用Time::HiRes 获得整数时间。但是,该模块中的clock_gettime() 可以解决问题。这是 perl 5.10.0
    • @Dallaylaen:您是否从 Time::HiRes 导出时间?
    • 谢谢,这是我的错误。当然use Time::HiRes qw/time/ 工作正常。
    【解决方案2】:

    一个真实的例子是:

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

    【讨论】:

      【解决方案3】:
      perl -MTime::HiRes=time -e 'print time;'
      

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-20
        • 2010-10-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-07
        • 2022-01-13
        • 1970-01-01
        相关资源
        最近更新 更多