time2Units.php能转换成哪些时间单位?

2026-04-03 04:481阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计208个文字,预计阅读时间需要1分钟。

time2Units.php能转换成哪些时间单位?

phpfunction convertTimeUnits($timeString, $unitMap) { foreach ($unitMap as $cn=> $u) { if ($timeString % $u==0) { $elapse=$timeString / $u . $cn; break; } } return $elapse;}

$unitArr=array( 'year'=> 365, 'month'=> 30, 'week'=> 7, 'day'=> 1, 'hour'=> 1/24, 'minute'=> 1/1440, 'second'=> 1/86400);

$elapseTime=convertTimeUnits(201, $unitArr);$past=strtotime('2021-01-01');

time2Units.php

'year', '个月'=>'month', '周'=>'week', '天'=>'day', '小时'=>'hour', '分钟'=>'minute', '秒'=>'second' ); foreach ( $unitArr as $cn => $u ){ if ( $$u > 0 ){ $elapse = $$u . $cn; break; } } return $elapse; } $past = strtotime("2017-01-12 21:49:00"); // Some timestamp in the past $now = time(); // Current timestamp $diff = $now - $past; echo '发表于' . time2Units($diff) . '前'; ?>

time2Units.php能转换成哪些时间单位?
标签:time2Unitsphp

本文共计208个文字,预计阅读时间需要1分钟。

time2Units.php能转换成哪些时间单位?

phpfunction convertTimeUnits($timeString, $unitMap) { foreach ($unitMap as $cn=> $u) { if ($timeString % $u==0) { $elapse=$timeString / $u . $cn; break; } } return $elapse;}

$unitArr=array( 'year'=> 365, 'month'=> 30, 'week'=> 7, 'day'=> 1, 'hour'=> 1/24, 'minute'=> 1/1440, 'second'=> 1/86400);

$elapseTime=convertTimeUnits(201, $unitArr);$past=strtotime('2021-01-01');

time2Units.php

'year', '个月'=>'month', '周'=>'week', '天'=>'day', '小时'=>'hour', '分钟'=>'minute', '秒'=>'second' ); foreach ( $unitArr as $cn => $u ){ if ( $$u > 0 ){ $elapse = $$u . $cn; break; } } return $elapse; } $past = strtotime("2017-01-12 21:49:00"); // Some timestamp in the past $now = time(); // Current timestamp $diff = $now - $past; echo '发表于' . time2Units($diff) . '前'; ?>

time2Units.php能转换成哪些时间单位?
标签:time2Unitsphp