是否有CPAN模块可将秒转换为英语? [英] Is there a CPAN module for converting seconds to English?

查看:87
本文介绍了是否有CPAN模块可将秒转换为英语?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个CPAN模块可以将秒数转换为人类可以理解的间隔时间的英语描述?

Is there a CPAN module that can convert a number of seconds to a human-readable English description of the interval?

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

该格式并不重要,只要它是人类可读的即可.

The format isn't important as long as it's human-readable.

我知道实现起来很简单.

I know that it would be trivial to implement.

推荐答案

自Perl v5.9.5起,模块Time :: Seconds和Time :: Piece是Perl核心发行版的一部分.因此,您可以在不安装其他模块的情况下使用它们.

Since Perl v5.9.5, the modules Time::Seconds and Time::Piece are part of the core Perl distribution. So you can use them without installing additional modules.

perl -MTime::Seconds -e 'my $s=125; my $ts=new Time::Seconds $s; print $ts->pretty, "\n"'
# 2 minutes, 5 seconds

perl -MTime::Seconds -e 'my $s=129_600; my $ts=Time::Seconds->new($s); print $ts->pretty, "\n"'
# 1 days, 12 hours, 0 minutes, 0 seconds

您还可以使用$ts->weeks$ts->minutes等之类的东西.

You can also use stuff like $ts->weeks, $ts->minutes, etc.

这篇关于是否有CPAN模块可将秒转换为英语?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆