找回密码
 立即注册
搜索
热搜: 活动 交友 discuz

destoon函数实现(获取几秒前、几分钟前、几小时前、几天前

[复制链接]
发表于 2020-9-15 23:42:43 | 显示全部楼层 |阅读模式
函数实现(获取几秒前、几分钟前、几小时前、几天前的时间)大于30天显示具体日期
需要在api/extend.func.php 文件中加入的函数
函数如下
  1. function time_tran($the_time)
  2. {
  3.     $now_time = time();
  4.     $show_time = strtotime($the_time);

  5.     $dur = $now_time - $show_time;

  6.     if($dur < 60){
  7.         return $dur.'秒前';
  8.     }else if($dur < 3600){
  9.         return floor($dur/60).'分钟前';
  10.     }else if($dur < 86400) {
  11.         return floor($dur/3600).'小时前';
  12.     }else if($dur < 259200) {//3天内
  13.         return floor($dur / 86400) . '天前';
  14.     }else{
  15.         return $the_time;
  16.     }
  17. }
复制代码
调取:
  1. {time_tran($adddate)}    添加时间
  2. {time_tran($editdate)}    更新时间
复制代码


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|知识在线

GMT+8, 2026-11-2 21:24 , Processed in 0.164975 second(s), 21 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表