Display time in ms in perl

I want to display time to millisecond. My code is giving error. Any other method is also appreciated.

use Time::HiRes qw/gettimeofday/;
use Time::Format qw/%time/;

$s1=gettimeofday;
print qq|$time{'yyyymmdd hh:mm:ss.mmm', $s1}\n|;

      

Mistake:

syntax error at (eval 2) line 31, near "->import qw(langinfo)"
        ...propagated at C:/Perl64/lib/Time/Format.pm line 77, <DATA> chunk 1.

      

+3


source to share


1 answer


Update your time :: Format. The version you are using is not working. This issue was corrected seven years ago. (at 1.07, March 31, 2008).

Or use the following:



use POSIX       qw( strftime );
use Time::HiRes qw( gettimeofday );

my ($secs, $microsecs) = gettimeofday();
strftime("%Y%m%d %H:%M:%S", localtime($secs)) . sprintf(".%03d", $microsecs/1000)

      

+5


source







All Articles