juniq / yii2-helper-time
Yii Framework 2 的一个用于时间计算的有用辅助函数,尤其是对持续时间来说
1.1
2015-08-18 09:17 UTC
Requires
This package is not auto-updated.
Last update: 2024-09-28 18:35:01 UTC
README
描述
Yii Framework 2 的一个用于时间计算的有用辅助函数,尤其是对持续时间来说。你可以使用函数 Time::formatDuration
将秒转换为人类可读的持续时间字符串,例如:5天8小时19分钟11秒
如何安装
Composer
安装此包最简单的方法是使用 Composer。如果你没有 Composer,可以在这里获取它
https://getcomposer.org.cn/download/
现在你可以在你的 项目根目录 中运行以下命令
composer require "juniq/yii2-helper-time" "*"
或(根据你的安装类型)
php composer.phar require "juniq/yii2-helper-time" "*"
手动下载
在此处下载最新版本
https://github.com/juniq/yii2-helper-time/
如何使用它
要将秒转换为人类可读的持续时间字符串,你可以使用以下函数
Time::formatDuration($time, $length = 'short', $custom_units = false, $separator = ', ')
示例
use juniq\helper\Time;
$time_in_seconds = 5781; // 1 hour 36 minutes, 21 seconds
echo Time::formatDuration($time_in_seconds);
// ouput: 1 hour 36 minutes, 21 seconds
echo Time::formatDuration($time_in_seconds, 'long', ['h','i','s'], 'long');
// ouput: 1 hour 36 minutes 21 seconds
echo Time::formatDuration($time_in_seconds, 'short', ['h','i','s'], ',');
// output: 36 minutes, 21 seconds
echo Time::formatDuration($time_in_seconds, 'short', ['i','s'], ',');
// output: 96 m, 21 s
许可证
查看 'LICENSE.md' 文件
关于 & 版权
版权所有 JUNIQ GmbH & Co. KG。作者:Richard Jung