Reputation: 1484
I want to display time till milliseconds. My code is giving error. Any other method is also welcome.
use Time::HiRes qw/gettimeofday/;
use Time::Format qw/%time/;
$s1=gettimeofday;
print qq|$time{'yyyymmdd hh:mm:ss.mmm', $s1}\n|;
Error:
syntax error at (eval 2) line 31, near "->import qw(langinfo)"
...propagated at C:/Perl64/lib/Time/Format.pm line 77, <DATA> chunk 1.
Upvotes: 3
Views: 422
Reputation: 385655
Update your Time::Format. The version you are using is buggy. The bug in question was fixed seven years ago. (in 1.07, on March 31st, 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)
Upvotes: 5