php 秒格式為天/小時/分鐘/秒
php 秒格式為天/小時/分鐘/秒
瞎弄的
/**
* PHP 格式化秒
*/
function vtime($time) {
$output = '';
foreach (array(86400 => '天', 3600 => '小時', 60 => '分', 1 => '秒') as $key => $value) {
if ($time >= $key) $output .= floor($time/$key) . $value;
$time %= $key;
}
return $output;
}
dida_bootstrap.inc
/**
* 計算給定的秒數距離當前時間多久
* @param int $timestamp
* 秒數,通常是當前時間減去另一個時間
* @param int $granularity
* 顯示層級,默認為 年 周 天 小時 分鐘 秒
* @return string
*/
function format_interval($timestamp, $granularity = 5) {
$units = array(
31536000 => t('system', '年'),
604800 => t('system', '周'),
86400 => t('system', '天'),
3600 => t('system', '小時'),
60 => t('system', '分鐘'),
1 => t('system', '秒')
);
$output = '';
foreach ($units as $key => $value) {
if ($timestamp >= $key) {
$output .= floor($timestamp / $key) . $value;
$timestamp %= $key;
$granularity--;
}
if ($granularity == 0) {
break;
}
}
return $output ? $output : t('system', '0 秒');
}
本文由用戶 ouhp9343 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!