Posted on 2009-10-30 14:32:40-07 by wyant in response to 11669
Re: Help converting time array to epoch time
If you would print the values you are sending to timelocal(), you would find that $time_array[5] was 109 (for another couple months), so $time_array[5]-1900 is -1791, which Time::Local can not deal with. Instead, try

$epoch_time_var = timelocal($time_array[0],$time_array[1],$time_array[2],$time_array[3],$time_array[4],$time_array[5]);

It turns out that

$epoch_time_var = timelocal(@time_array)

works just as well, though the truly paranoid would say

$epoch_time_var = timelocal(@time_array[0..5]);

You could also try

use Time::y2038;

instead of Time::Local if you have Time::y2038 installed, and if you are worried about dates outside the range 1970 to 2038.
Direct Responses: 11672 | Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.