1. 程式人生 > >php 解決date('Y-m',strtotime('-1 month'))

php 解決date('Y-m',strtotime('-1 month'))

/**
 * 解決2017-01-31 -1 month)還顯示1月的問題
*/
$data = "2017-1-31";
$base = strtotime(date('Y-m',strtotime($data)) . '-01 00:00:01');
echo date('Y-m',strtotime('-1 month', $base));