Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to get Epoch milliseconds in Perl?

It's easy to get Epoch-Seconds (timestamp) in perl:

time

But what's with milliseconds? The most effective way seems to be time*1000, but that's not as accurate as I want it to be. Any good hints except for the long terms documented @perldoc?

like image 347
xsigndll Avatar asked Feb 27 '11 17:02

xsigndll


People also ask

How do I get current epoch time in Perl?

You can use the time() function in Perl to get epoch time, i.e., the numbers of seconds that have elapsed since a given date, in Unix is January 1, 1970.

Is epoch milliseconds or seconds?

In computing, Unix time (also known as Epoch time, Posix time, seconds since the Epoch, Unix timestamp or UNIX Epoch time) is a system for describing a point in time. It is the number of seconds that have elapsed since the Unix epoch, excluding leap seconds. The Unix epoch is 00:00:00 UTC on 1 January 1970.

Are epoch timestamps always UTC?

In a computing context, an epoch is the date and time relative to which a computer's clock and timestamp values are determined. The epoch traditionally corresponds to 0 hours, 0 minutes, and 0 seconds (00:00:00) Coordinated Universal Time (UTC) on a specific date, which varies from system to system.


1 Answers

The Time::HiRes module has a drop-in replacement for time

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

You can read more in the perl FAQ

perldoc -q "How can I measure time under a second"
like image 130
oylenshpeegul Avatar answered Oct 12 '22 11:10

oylenshpeegul