- Perl ›
- builtin functions ›
- here
time function - Get the number of seconds elapsed from the epoch to the present
You can use the time function to get the number of seconds elapsed from the epoch to the present. An epoch is a point in time that serves as a reference for time. In many systems, the epoch is January 1, 1970, 0:00:00:00, Coordinated Universal Time.
my $sec_from_epoch = time;
You can use the time function to get the number of seconds counted from the epoch. This number of seconds is slightly different from the actual time because leap seconds are not taken into account. (Leap seconds are seconds that are inserted every few years to adjust the time because the rotation of the earth is delayed every year.)
For general information about dates and times, please refer to the following.
What is an epoch?
An epoch is a point in time that serves as a reference for time. In many systems, the epoch is January 1, 1970, 0:00:00:00, Coordinated Universal Time.
Time range
On a 32-bit machine, the time from -2,147,483,648 seconds to 2,147,483,647 seconds can be expressed based on the epoch.
The date will be from December 13, 1901 (Friday) 20:45:52 to January 19, 2038 (Tuesday) 3:14:07 (Coordinated Universal Time). Calculation of time beyond this range cannot be performed with Perl builtin functions.
Time function example
This is an example using the time function.
use strict; use warnings; # Get the number of seconds elapsed from the epoch to the present time my $sec_from_epoch = time; print "$sec_from_epoch sec\n";