Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Find time after current time

by Anonymous Monk
on Jun 28, 2006 at 22:06 UTC ( #558170=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,
I have to find the time 2 minutes after the current time.Eg.Let us assume the current timestamp is,20060629 06:58:00.I have to increement 2 minutes and i want to get 20060629 07:00:00.
How we do this.Any modules availabe for this. Expecting your reply.

Comment on Find time after current time
Re: Find time after current time
by qsl (Scribe) on Jun 28, 2006 at 22:08 UTC
    Hello,
    Use the Date::calc () and try to do this........
    Regards,
    qsl.
Re: Find time after current time
by ioannis (Priest) on Jun 28, 2006 at 22:35 UTC
    It can be as simple as this; or, format it accordingly:

    print scalar localtime(time+(60*2));

Re: Find time after current time
by johngg (Abbot) on Jun 28, 2006 at 22:37 UTC
    You can split the timestamp up into year, month etc. and use the timelocal() subroutine of the Time::Local module (comes with Perl) to convert the timestamp to seconds since the epoch. Then add 120 to go forward two minutes and use localtime() to convert back to seconds, minutes etc.

    Be sure to watch out for years counting from 1900, e.g. 2006 should be supplied to timelocal() as 106 and you'll get the same back from localtime(). Also January is 0, December is 11.

    I hope this is of use.

    Cheers,

    JohnGG

Re: Find time after current time
by saintmike (Vicar) on Jun 28, 2006 at 22:56 UTC
    Date calculations can be surprisingly tricky.

    Pop quiz: What time do you get when you add 2 seconds to 03:59:59 pm on 31/12/2005 in the PST timezone? Let's find out:

    use DateTime; my $dt = DateTime->new( year => 2005, month => 12, day => 31, hour => 15, minute => 59, second => 59, time_zone => "America/Los_Angeles", ); $dt->add(seconds => 2); print "$dt\n";
    Result is 2005-12-31T16:00:00 since there was a leap second in between.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://558170]
Approved by Paladin
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (10)
As of 2014-07-28 10:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (195 votes), past polls