Posted on 2009-10-30 13:33:55-07 by bruhnf
Help converting time array to epoch time
I am trying to convert a time array to epoch time. If I execute the following code with the time hard coded in the fields, I get the correct epoch time returned. Obviously, I had to subtract 1 for the month and 109 for the year (ie: 2009)
$epoch_time_var = timelocal(59,04,10,30,9,109); print "$epoch_time_var \n";
This prints 1256911934 (the correct epoch time that I hard coded in) but... If I try to use the elements of a time array to do the same thing, I get the error cannot handle date at line xxx.
my @time_array = localtime(time); $epoch_time_var = timelocal($time_array[0],$time_array[1],$time_array[2],$time_array[3],$time_array +[4]-1,$time_array[5]-1900); print "$epoch_time_var \n";
Any idea why this doesn't work and how to make it work? Thanks in advance for any help on this. Bruhn
Direct Responses: 11671 | 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.