• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

PHP 计算当前时间和发布时间相差的时间

武飞扬头像
Luke
帮助12483

/**
 * [计算当前时间和发布时间相差的时间]
 * @E-mial wuliqiang_aa@163.com
 * @TIME   2017-04-07
 * @WEB    http://www.swvq.com
 * @param  [正常格式时间] $the_time [发布的时间]
 * @return [时间戳]$show_time      [发布的时间 ]
 * @return [时间戳]$now_time      [现在的时间 ]
 * @php 单位为秒
 */
function time_tran($the_time)
{
    //现在的时间
    $now_time = strtotime(date("Y-m-d H:i:s",time() 8*60*60));
    //发布的时间
    $show_time = strtotime($the_time);
    //计算相差天数
    $dur = $now_time - $show_time;
    //返回相应的时间
    switch ($dur) {
        case $dur < 0:return $the_time;break;//无变化
        case $dur < 60:return $dur.'秒前';break;//多少秒前
        case $dur < 3600:return floor($dur/60).'分钟前';break;//分钟前
        case $dur < 86400:return floor($dur/3600).'小时前';break;//小时前
        case $dur < 259200:return floor($dur/86400).'天前';break;//天前
        case $dur < 864000:return floor($dur/86400).'天前';break;//10天内
        case $dur < 1728000:return floor($dur/86400).'天前';break;//20天内
        case $dur < 2592000:return floor($dur/86400).'天前';break;//30天后
        case $dur < 2764800:return '1个月前';break;//1个月前
        default:return floor($dur/2764800).'个月前';break;
    }
}


这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/taneeah
系列文章
更多 icon
同类精品
更多 icon
继续加载