PHP日期处理

// 前n天 
echo date("Y-m-d", strtotime('-n day'));

// 后n天
echo date("Y-m-d", strtotime('+n day'));

//本周一
echo date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600));

//本周日
echo date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600));

//上 n 周一
echo date('Y-m-d', strtotime('-n monday', time()));

//上 n 周日
echo date('Y-m-d', strtotime('-n sunday', time()));

//上n周同天
echo date('Y-m-d', strtotime("-7*n day"));

//本月一号
echo date('Y-m-01');

//本月最后一天
echo date("Y-m-d", strtotime(date("Y-m-01",strtotime("+1 month")))-86400);
echo date('Y-m-d', strtotime(date('Y-m', time()) . '-' . date('t', time()) . ' 00:00:00'));30

//上月一号
echo date('Y-m-01', strtotime('-1 month'));

//上月最后一天
echo date("Y-m-d",strtotime(date("Y-m-01")) - 86400);
echo date('Y-m-d', strtotime(date('Y-m', time()) . '-01 00:00:00') - 86400);

//-2月一号
echo date('Y-m-01', strtotime('-2 month'));

//-2月最后一天
echo date("Y-m-d",strtotime(date('Y-m-01', strtotime('-2 month'))) - 86400);

//上月今天
echo date("Y-m-d", strtotime('-1 month'));

//12月第二个周日
echo date("Y-m-d", strtotime("Second Monday of ".date("Y-12")));
posted @ 2019-12-12 11:44  JamesVie  阅读(104)  评论(0编辑  收藏  举报