use strict; use warnings; # Need this to turn date into seconds since epoch. Standard # part of Perl distribution. # use Time::Local; # Initialise date string, print it and then increment by # fifteen minutes and print ten times just to show it works. # our $dateStr = "200604132341"; print "$dateStr\n"; $dateStr = plus15($dateStr), print "$dateStr\n" for 1 .. 10; sub plus15 { # Get date string, set seconds to zero, pull the rest of # the date from the string with a match; # my $dateStr = shift; my $sec = 0; my ($year, $mth, $day, $hr, $min) = $dateStr =~ /^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)$/; # Get seconds since the epoch, note months start from zero for # January to 11 for December. Add 15 minutes-worth of seconds. # my $timeVal = timelocal($sec, $min, $hr, $day, $mth - 1, $year); $timeVal += 15 * 60; # Turn back in to separate parts, year, month etc. Note that # localtime() returns years since 1900. Construct a new date # string and return it. # my @timeParts = localtime($timeVal); my $newStr = $timeParts[5] + 1900 . sprintf("%02d", $timeParts[4] + 1) . sprintf("%02d", $timeParts[3]) . sprintf("%02d", $timeParts[2]) . sprintf("%02d", $timeParts[1]); return $newStr; }