sureshrps has asked for the wisdom of the Perl Monks concerning the following question:

Hi, If current time is 08:05:36, I want it to read 09:05:36 How can I accomplish this? Regards Suresh
  • Comment on How can I add 1 hour to the current time

Replies are listed 'Best First'.
Re: How can I add 1 hour to the current time
by Perlbotics (Archbishop) on Aug 20, 2011 at 08:33 UTC

    What have you tried? Here are some hints in case you have problems getting started:

    1. If you have the epoch (seconds since 01-01-1970) at hand, add 3600 seconds and render output again.
    2. If not, convert your date into an epoch and proceed with previous step.
    3. Regexp might work. Hints: perlre ('e' switch); sprintf
    4. Have a look at CPAN modules. Maybe Date::Manip or Date::Time is something for you?

    What's wrong with the advice given in How to get current UK time?

    HTH

Re: How can I add 1 hour to the current time
by GrandFather (Saint) on Aug 20, 2011 at 08:22 UTC
    print scalar localtime time + 3600;

    But maybe you want something else, in which case you should show us what you've got or tell us more about what you want.

    True laziness is hard work
      Thanks for the reply. I want London time. Hence i used the following code to find. $now = gmtime() ; print $now; the print is "Sat Aug 20 08:26:46 2011". This is GMT time. London Current time zone is UTC/GMT +1 hour. Hence I need to add 1 hour. Regards Suresh

        Wouldn't it be easier to just get the time in London?

        use DateTime; my $dt = DateTime->now( time_zone => 'Europe/London' ); say $dt->strftime('%Y-%m-%d %H:%M:%S');
Re: How can I add 1 hour to the current time
by ikegami (Patriarch) on Aug 20, 2011 at 08:44 UTC
    use DateTime; my $dt = DateTime->now( time_zone => 'local' ); $dt->add( hours => 1 ); say $dt->strftime('%Y-%m-%d %H:%M:%S');
      say $dt->ymd;

      Shouldn't that be: say $dt->hms;


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Fixed, thanks
Re: How can I add 1 hour to the current time
by muba (Priest) on Aug 21, 2011 at 03:51 UTC

    Well, that is partially correct. London time is GMT, but not just now because Londen (as most —if not all— of Western Europe) is in Daylight Saving Time. The second DST ends for England, adding an hour to the current time would give wrong results if what you want is "London time." DateTime knows about DST details — which varies between one country and another! Although the EU is, as I recall, pretty consistent about it — so you really should look into it.