本文共 1573 字,大约阅读时间需要 5 分钟。
1.获取本周开始和结束的日期:
echo date("y-m-d h:i:s", mktime(0,0,0,date("m"),date("d")-date("w")+1,date("y"))); //2020-03-09 00:00:00
echo date("y-m-d h:i:s", mktime(23,59,59,date("m"),date("d")-date("w")+7,date("y"))); //2020-03-15 23:59:59
2.获取上周开始和结束的日期:
echo date('y-m-d h:i:s', mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('y'))); //2020-03-02 00:00:00
echo date('y-m-d h:i:s', mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('y'))); //2020-03-08 23:59:59
3.获取本月开始和结束的日期:
echo date('y-m-d h:i:s', mktime(0,0,0,date('m'),1,date('y'))); //2020-03-01 00:00:00
echo date('y-m-d h:i:s', mktime(23,59,59,date('m'),date('t'),date('y'))); //2020-03-31 23:59:59
4.获取上月开始和结束的日期:
echo date("y-m-d h:i:s", mktime(0,0,0,date("m")-1,1,date("y"))); //2020-02-01 00:00:00
echo date("y-m-d h:i:s", mktime(23,59,59,date("m") ,0,date("y"))); //2020-02-29 23:59:59
5.获取本季度开始和结束的日期:
$season = ceil((date('n'))/3);
echo date('y-m-d h:i:s', mktime(0,0,0,$season*3-3+1,1,date('y'))); //2020-01-01 00:00:00
echo date('y-m-d h:i:s', mktime(23,59,59,$season*3,date('t',mktime(0,0,0,$season*3,1,date("y"))),date('y'))); //2020-03-31 23:59:59
6.获取上季度开始和结束的日期:
$season = ceil((date('n'))/3)-1;//上季度是第几季度
echo date('y-m-d h:i:s', mktime(0,0,0,$season*3-3+1,1,date('y'))); //2019-10-01 00:00:00
echo date('y-m-d h:i:s', mktime(23,59,59,$season*3,date('t',mktime(0,0,0,$season*3,1,date("y"))),date('y')));//2019-12-31 23:59:59
7.获取本月是第几月:
echo date('n'); //3
8.获取今天是周几:
echo date("w"); //4
9.获取本月总天数:
echo date("t"); //31
希望与广大网友互动??
点此进行留言吧!
转载地址:http://fkrav.baihongyu.com/