php计算时间函数:几分钟前、几小时前、几天前
内容摘要
这篇文章主要为大家详细介绍了php计算时间函数:几分钟前、几小时前、几天前,具有一定的参考价值,可以用来参考一下。
经测试后的代码如下:
<?php
function time_tran($the_tim
经测试后的代码如下:
<?php
function time_tran($the_tim
文章正文
这篇文章主要为大家详细介绍了php计算时间函数:几分钟前、几小时前、几天前,具有一定的参考价值,可以用来参考一下。
经测试后的代码如下:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <code class = "php" > <?php function time_tran( $the_time ) { $now_time = date ( "Y-m-d H:i:s" , time()); //echo $now_time; $now_time = strtotime ( $now_time ); $show_time = strtotime ( $the_time ); $dur = $now_time - $show_time ; if ( $dur < 0) { return $the_time ; } else { 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 ; } } } } } } ?> </code> |
注:关于php计算时间函数:几分钟前、几小时前、几天前的内容就先介绍到这里,更多相关文章的可以留意
代码注释