• 函数实现(获取几秒前、几分钟前、几小时前、几天前的时间)


     函数实现(获取几秒前、几分钟前、几小时前、几天前的时间)大于30天显示具体日期

    类似:


    需要在api/extend.func.php 文件中加入的函数

    函数如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    function time_tran($the_time)
    {
        $now_time = time();
        $show_time strtotime($the_time);
      
        $dur $now_time $show_time;
      
        if($dur < 60){
            return $dur.'秒前';
        }else if($dur < 3600){
            return floor($dur/60).'分钟前';
        }else if($dur < 86400) {
            return floor($dur/3600).'小时前';
        }else if($dur < 259200) {//3天内
            return floor($dur / 86400) . '天前';
        }else{
            return $the_time;
        }
    }

    调取如下:

    1
    2
    {time_tran($adddate)}    添加时间
    {time_tran($editdate)}    更新时间
  • 相关阅读:
    http参数传递方式
    Api接口管理工具推荐
    IntelliJ IDEA 插件推荐
    spring服务器接收参数格式
    SSM框架的常用注解整理
    Java map 详解
    遍历Map集合四中方法
    bean对应mapper.xml字段
    Java简历与面试
    SQL的case when then else end语句的用法
  • 原文地址:https://www.cnblogs.com/68xi/p/16301829.html
Copyright © 2020-2023  润新知