当前位置 : 主页 > 网络编程 > PHP >

time2Units.php

来源:互联网 收集:自由互联 发布时间:2021-06-28
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("201
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) . '前';

?>
网友评论