Heim >Backend-Entwicklung >PHP-Tutorial >php时间调用有关问题
php时间调用问题
对php编程一点不懂,请教:
想实现,*分钟前(*小时前...),不知道怎么编,在网上找到一段代码,很好用,也很简单:
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php function format_time($time){ $t=time()-$time; $f=array( '31536000'=>'年', '2592000'=>'个月', '604800'=>'星期', '86400'=>'天', '3600'=>'小时', '60'=>'分钟', '1'=>'秒' ); foreach ($f as $k=>$v) { if (0 != $c=floor($t/(int)$k)) { return $c.$v.'前'; } } } echo format_time('1336880454'); ?>
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php $time1 = "2012-05-13 11:40:54";$time2 = strtotime($time1);echo $time2;//转换成时间戳格式echo date('',$time2);//转换成标准日期格式?>
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php while ($row = mysql_fetch_array($rs_tmmsm)) {?>=date("Y-m-d <!--h:i-->",strtotime($row["pay_time"]))?><?php }?>
<?php function format_time($time){ $t=time()-$time; $f=array( '31536000'=>'年', '2592000'=>'个月', '604800'=>'星期', '86400'=>'天', '3600'=>'小时', '60'=>'分钟', '1'=>'秒' ); foreach ($f as $k=>$v) { if (0 != $c=floor($t/(int)$k)) { return $c.$v.'前'; } } } while ($row = mysql_fetch_array($rs_tmmsm)) { echo format_time(strtotime($row["pay_time"]));}?><div class="clear"> </div>