in reply to Re^2: Finding Time Difference of Localtime
in thread Finding Time Difference of Localtime

Whoops! Thank you for checking this, that's not what I want.

You want to use time, not gmtime, and use strftime( localtime( $start )) to turn the seconds back into strings.

I'll fix the above post.

Replies are listed 'Best First'.
Re^4: Finding Time Difference of Localtime
by Aldebaran (Curate) on Dec 03, 2019 at 19:56 UTC
    You want to use time, not gmtime, and use strftime( localtime( $start )) to turn the seconds back into strings.

    That gets us there:

    $ ./2.strftime.pl It took me 10 seconds I was started on 2019-12-03 11:41:38 and ended on 2019-12-03 11:41:48 $ cat 2.strftime.pl
    #!/usr/bin/perl use strict; use warnings; use POSIX qw(strftime); my $start = time(); sleep 10; my $end = time(); my $duration = $end - $start; print "It took me $duration seconds\n"; my $start_date = strftime "%Y-%m-%d %H:%M:%S",(localtime($start)); my $end_date = strftime "%Y-%m-%d %H:%M:%S",(localtime($end)); print "I was started on $start_date and ended on $end_date\n";
    I'll fix the above post.

    Fixing a post from 2010 might have a butterfly effect. Getting better behavior from output is what happens with code review and replication in "the monastery."