in reply to Finding Time Difference of Localtime
Don't use localtime in the first place. Use time or gmtime and POSIX::strftime instead.
#!/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";
Updated after Aldebaran actually checked the code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Finding Time Difference of Localtime
by Aldebaran (Curate) on Dec 01, 2019 at 00:42 UTC | |
by Corion (Patriarch) on Dec 01, 2019 at 08:01 UTC | |
by Aldebaran (Curate) on Dec 03, 2019 at 19:56 UTC |