周月时间获取

php php 796      收藏
周月时间获取

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)); //本周日
echo '上周一:'.date('Y-m-d', strtotime('-2 monday', time())); //上周一
echo '上周日:'.date('Y-m-d', strtotime('-1 sunday', time())); //上周日

echo '本月一日:'.date('Y-m-d', strtotime(date('Y-m', time()) . '-01 00:00:00')); //本月一日
echo '本月最后一日:'.date('Y-m-d', strtotime(date('Y-m', time()) . '-' . date('t', time()) . ' 00:00:00')); //本月最后一日

echo '上月一日:'.date('Y-m-d', strtotime('-1 month', strtotime(date('Y-m', time()) . '-01 00:00:00'))); //上月一日

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