2

In php you could just do

strtotime("+1 days");

And get the machine time for the next day.

I want to try the same with Perl, I'm going to be doing a sort of cron job to execute certain methods.

I know you could it use str2time from the module http://search.cpan.org/~gaas/HTTP-Date-6.02/lib/HTTP/Date.pm I just can't seem to figure it out.

I tried the following, but I'm unsure if I did it right

use HTTP::Date qw(str2time);
use Time::Piece;
use Time::Seconds;

my $lol = localtime();
my $time = $lol - ONE_HOUR*($lol->hour + 24);

print "Time: " . str2time($time);
Hunter McMillen
  • 59,865
  • 24
  • 119
  • 170
user2524169
  • 267
  • 1
  • 2
  • 12
  • 2
    Be careful, a day is not always 24 hours long if your time zone has daylight savings. If your system's time zone is set to UTC, you don't have to worry. – ThisSuitIsBlackNot Nov 07 '14 at 21:31

2 Answers2

5
use Time::Piece;
use Time::Seconds;

my $t1 = localtime() + ONE_DAY;

print $t1->epoch;
mpapec
  • 50,217
  • 8
  • 67
  • 127
1

Tool for the job here is Time::Piece.

#!/usr/bin/perl
use strict;
use warnings;

use Time::Piece;

my $this_time = localtime();
print $this_time + 60*60*24,"\n";
Sobrique
  • 52,974
  • 7
  • 60
  • 101