PHP获取时间

<?php

header("content-type:text/html;charset=utf-8");


//PRC代指中国时间,添加后可以正确获取中国时间
date_default_timezone_set('PRC');

//获取当前电脑的时间
echo '现在的时间是:'.date('Y-m-d H:i:s');
echo '<br>';echo '<br>';

//获取昨天的现在时间(方法1)
echo '昨天的现在的时间是:'.date('Y-m-d H:i:s', strtotime('-1 day'));
echo '<br>';
//获取昨天的现在时间(方法2)
echo '昨天的现在的时间是:'.date('Y-m-d H:i:s', time()-86400);
echo '<br>';

//获取上一周的现在时间
echo '上一周的现在的时间是:'.date('Y-m-d H:i:s', strtotime('-1 week'));
echo '<br>';

//获取上周二的现在时间
echo '上周二的现在的时间是:'.date('Y-m-d', strtotime('last Tuesday -1 week')).date(' H:i:s');
echo '<br>';

//获取明天的现在时间(方法1)
echo '明天的现在的时间是:'.date('Y-m-d H:i:s', strtotime('+1 day'));
echo '<br>';
//获取明天的现在时间(方法2)
echo '明天的现在的时间是:'.date('Y-m-d H:i:s', time()+86400);
echo '<br>';

//获取下一周的现在时间
echo '下一周的现在的时间是:'.date('Y-m-d H:i:s', strtotime('+1 week'));
echo '<br>';

//获取下周一的现在时间
echo '下周一的现在的时间是:'.date('Y-m-d', strtotime('next Monday')).date(' H:i:s');
echo '<br>';

//显示本月的第一天的日期
echo '本月第一天是:'.date('Y-m-01');
echo '<br>';

//显示本月的最后一天的日期
echo '本月最后一天是:'.date('Y-m-t');
echo '<br>';

?>

 

posted @ 2016-04-27 09:00  库洛里德  阅读(2079)  评论(0编辑  收藏  举报