qq说说时间轴php实现,PHP通用函数 - 日期生成时间轴

http://www.cnblogs.com/showblog/p/4350177.html

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 }

转载于:https://www.cnblogs.com/showblog/p/4350177.html

标签:idate,函数,seconds,days,break,时间轴,time,message,PHP

来源: https://blog.csdn.net/weixin_30741653/article/details/98202091

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值