You can use the timelocal function in the CPAN module Time :: Local .
NAME
Time :: Local - effective calculation of time from local and GMT
SYNTAX
$time = timelocal($sec,$min,$hour,$mday,$mon,$year); $time = timegm($sec,$min,$hour,$mday,$mon,$year);
DESCRIPTION
This module provides functions that are the inverted perl built-in functions of localtime () and gmtime (). They take the date as a six-element array and return the corresponding time (2) in seconds since the system era (Midnight, January 1, 1970 GMT on Unix, for example). This value can be positive or negative, although POSIX requires support only for positive values, so dates before the system era may not work on all operating systems.
It is worth paying particular attention to the expected ranges for the values provided. The value for the day of the month is the actual day (i.e. 1..31), and the month is the number of months since January (0.11). This is consistent with the return values from localtime () and gmtime ().
Note: POSIX :: mktime is just a wrapper around your C mktime() library. Time :: Local is a pure-Perl implementation and always returns results matching Perl localtime . In addition, Time :: Local offers gmtime , while mktime only works in local time. (Well, you can try changing $ENV{TZ} , but this does not work on some systems.)
Robert S. Barnes
source share