在php日期函数中,常用的函数为date函数、php时间戳函数(strtotime函数、mktime函数)等。
这里举一个例子,来看看PHP获取本周与上周时间段的方法。
代码:
<?php
/*
* php日期函数
**/
echo date("Ymd",strtotime("now")), "n";
echo date("Ymd",strtotime("-1 week Monday")), "n";
echo date("Ymd",strtotime("-1 week Sunday")), "n";
echo date("Ymd",strtotime("+0 week Monday")), "n";
echo date("Ymd",strtotime("+0 week Sunday")), "n";
$getWeekDay=date("w");
echo date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$getWeekDay+1-7,date("Y"))),"n";
echo date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$getWeekDay+7-7,date("Y"))),"n";
echo date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$getWeekDay+1,date("Y"))),"n";
echo date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$getWeekDay+7,date("Y"))),"n";
?>