Remember to subtract 1900 from the year!
Remember that in the scalar context, localtime and gmtime returns a ctime formatted string, so you can use it as shown below. If this is unsuitable, you can use strftime from the POSIX module.
#! /usr/bin/perl use warnings; use strict; use Time::Local; my $start = "01:02:03"; my $end = "01:02:05"; my $date = "2010-02-10"; my($year,$mon,$mday) = split /-/, $date; $mon--; $year -= 1900; my($startTime,$endTime) = map { my($hour,$min,$sec) = split /:/; timelocal $sec,$min,$hour,$mday,$mon,$year } $start, $end; for (my $i = $startTime; $i <= $endTime + 29; $i++) { print scalar localtime($i), "\n"; } print "$startTime $endTime \n";
Output Tail:
Wed Feb 10 01:02:26 2010
Wed Feb 10 01:02:27 2010
Wed Feb 10 01:02:28 2010
Wed Feb 10 01:02:29 2010
Wed Feb 10 01:02:30 2010
Wed Feb 10 01:02:31 2010
Wed Feb 10 01:02:32 2010
Wed Feb 10 01:02:33 2010
Wed Feb 10 01:02:34 2010
1265785323 1265785325
Greg bacon
source share