gpt4 book ai didi

perl - 是否有用于将秒数转换为英语的 CPAN 模块?

转载 作者:行者123 更新时间:2023-12-04 16:17:07 26 4
gpt4 key购买 nike

是否有可以将秒数转换为人类可读的间隔英文描述的 CPAN 模块?

secToEng( 125 ); # => 2 min 5 sec
secToEng( 129_600 ); # => 1 day 12 h

格式并不重要,只要它是人类可读的。

我知道实现起来很简单。

最佳答案

原来Time::Duration正是这样做的。

$ perl -MTime::Duration -E 'say duration(125)'
2 minutes and 5 seconds
$ perl -MTime::Duration -E 'say duration(129_700)'
1 day and 12 hours

来自简介:

Time::Duration - rounded or exact English expression of durations

Example use in a program that ends by noting its runtime:

my $start_time = time();
use Time::Duration;
# then things that take all that time, and then ends:
print "Runtime ", duration(time() - $start_time), ".\n";

Example use in a program that reports age of a file:

use Time::Duration;
my $file = 'that_file';
my $age = $^T - (stat($file))[9]; # 9 = modtime
print "$file was modified ", ago($age);

关于perl - 是否有用于将秒数转换为英语的 CPAN 模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7545664/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com