• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP通用函数 - 日期生成时间轴

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
 1 /**
 2  * 时间轴函数, Unix 时间戳
 3  * @param int $time 时间
 4  */
 5 function TranTime($time) {
 6     //$time = strtotime($time);
 7     $nowTime = time (); 
 8     $message = ''; 
 9     //一年前
10     if (idate ( 'Y', $nowTime ) != idate ( 'Y', $time )) {
11         $message = date ( 'Y年m月d日', $time );
12     }
13     else {
14         //同一年
15         $days = idate ( 'z', $nowTime ) - idate ( 'z', $time );
16         switch(true){
17             //一天内
18             case (0 == $days):
19                 $seconds = $nowTime - $time;
20                 //一小时内
21                 if ($seconds < 3600) {
22                     //一分钟内
23                     if ($seconds < 60) {
24                         if (3 > $seconds) {
25                             $message = '刚刚';
26                         } else {
27                             $message = $seconds . '秒前';
28                         }
29                     }
30                     $message = intval ( $seconds / 60 ) . '分钟前';
31                 }
32                 $message = idate ( 'H', $nowTime ) - idate ( 'H', $time ) . '小时前';
33                 break;
34                 //昨天
35             case (1 == $days):
36                 $message = '昨天' . date ( 'H:i', $time );
37                 break;
38                 //前天
39             case (2 == $days):
40                 $message = '前天 ' . date ( 'H:i', $time );
41                 break;
42                 //7天内
43             case (7 > $days):
44                 $message = $days . '天前';
45                 break;
46                 //超过7天
47             default:
48                 $message = date ( 'n月j日 H:i', $time );
49                 break;
50         }
51     }
52     return $message;
53 }

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
算法提炼是落脚点-php数组-字符串函数发布时间:2022-07-10
下一篇:
PHP微信开发入门之关注回复(一) - 飞羽哥哥发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap