【发布时间】:2020-08-09 07:11:37
【问题描述】:
我在玩 POSIX qw{strftime}; 以用作程序的正常运行时间,但我发现了一些我不知道为什么会发生的事情。我不怎么花时间,这就是我搞砸它的原因(学习填补“时间”:P)
数学给了我| uptime: 01:00:00我应该在哪里00:00:00我输入了
$stop_secs = $stop_secs - "3600"; 并“修复”了它,但我想知道额外的时间是从哪里来的。
我不知道为什么,谁能解释一下或者为什么会这样?谢谢。
#!/usr/bin/perl
#
use strict;
use warnings;
use POSIX qw{strftime};
my $start_secs = time();
my $start_time = strftime '%H:%M:%S', localtime $start_secs; # all is: "%Y-%m-%d %H:%M:%S"
my $stop_secs = time();
$stop_secs = $stop_secs - "3600"; #<--- this fix the 1h "bug"?
my $diff_secs = $stop_secs - $start_secs;
my $diff_time = strftime '%H:%M:%S', localtime $diff_secs;
print "
| Time started: $start_time
| uptime: $diff_time
\n";
【问题讨论】:
标签: perl math time strftime seconds