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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。