PHP日付処理

1483 ワード

//  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")));