
FishMonger
Veteran
/ Moderator
Dec 26, 2012, 2:13 PM
Post #4 of 5
(3835 views)
|
Re: [cuboidgraphix] Need a script to increment date and time by 30 minutes
[In reply to]
|
Can't Post
|
|
If you use the Mktime function from the Date::Calc module instead of the POSIX function, you won't need to adjust the values to conform to what the POSIX mktime function expects. Here's a short test script example;
#!/usr/bin/perl use v5.10.1; use strict; use warnings; use POSIX qw(strftime); use Date::Calc qw(Mktime); use Data::Dumper; my $start = '17/12/2012 00:30:00'; my ($day,$mon,$yr,$hr,$min,$sec) = split(/[\/ :]/, $start); my $time = Mktime($yr,$mon,$day, $hr,$min,$sec); for (1..10) { say scalar localtime($time); $time += 60*30; } Output: c:\testing>perl-1.pl
Mon Dec 17 00:30:00 2012 Mon Dec 17 01:00:00 2012 Mon Dec 17 01:30:00 2012 Mon Dec 17 02:00:00 2012 Mon Dec 17 02:30:00 2012 Mon Dec 17 03:00:00 2012 Mon Dec 17 03:30:00 2012 Mon Dec 17 04:00:00 2012 Mon Dec 17 04:30:00 2012 Mon Dec 17 05:00:00 2012
|