【php基础】php常用时间函数
1·获取时间
time()
获取当前时间,最小单位是秒
microtime()
获取当前时间,最小单位是微妙;
microtime()--------0.1615 1561651
microtime(true)----1561651.1615
2·格式化时间
date()
date('Y-m-d H:i:s',time());格式化时间为:年-月-日 小时:分钟:秒
w -- 星期中的第几天
z -- 年份中的第几天
......
3·显示前一天的时间
date('Y-m-d H:i:s',(time()-24*60*60));
或者
date('Y-m-d H:i:s',strtotime('-1 day'));
4·计算时间差
- function getDifference($endDate,$startDate){
- $start = strtotime($startDate);
- $end = strtotime($endDate);
- $date=floor(($end-$start)/86400);
- $hour=floor(($end-$start)%86400/3600);
- $minute=floor(($end-$start)%86400/60);
- $second=floor(($end-$start)%86400%60);
- return array('day'=>$date,'hour'=>$hour,'minute'=>$minute,'second'=>$second);
- }
注:这段代码参考了网上的代码

浙公网安备 33010602011771号