A common requirement in programs is getting the number of seconds, milliseconds, or nanoseconds since the Unix epoch. Here’s how to do it in Perl.
In Perl, we use the Time::HiRes module to get high-resolution time. The time function from this module returns the current time as a floating-point number of seconds since the Unix epoch.
We can then manipulate this value to get seconds, milliseconds, or nanoseconds. To convert back to a human-readable time format, we use the localtime function.
Here’s what the output might look like:
Note that the exact values will depend on when you run the script.
Next, we’ll look at another time-related task: time parsing and formatting.