重複の可能性:
php で指定された月の翌月と前月
私はこのコードを使用します:
$prev_month = strtolower(date('F',strtotime('February - 1 month')));
月を3月に変更しても、常に12月に戻ります。
助けてください!
重複の可能性:
php で指定された月の翌月と前月
私はこのコードを使用します:
$prev_month = strtolower(date('F',strtotime('February - 1 month')));
月を3月に変更しても、常に12月に戻ります。
助けてください!
$currentMonth = date('F');
echo Date('F', strtotime($currentMonth . " last month"));
現在の月を基準にしたくない場合は、次のように設定します。
$currentMonth = 'February';
// outputs January
strtotime()
理解する'last month'
。
$last_month = date('F', strtotime('last month'));
\DateTime
次のクラスを使用することもできます。
$date_time = new \DateTime('last month');
$last_month = $date_time->format('F');
それはあなたが必要とするものに依存します。前月の名前だけが必要な場合は、最初の例で問題ありません。日付を操作したい場合(1年の月をループするなど)、\DateTime
クラスを使用すると非常に簡単になります。
このコードを使用してください
$submonth = date("F", strtotime ( '-1 month' , strtotime ( 'February' ) )) ;
echo $submonth;
次のコードを使用します。
echo date("F", time()-date("j")*24*60*60);
以下も使用できます。
echo date("F", strtotime("last month"));
PHP コード
$days_passed_this_month = date("j");
$timestamp_last_month = time() - $days_passed_this_month *24*60*60;
$last_month = date("F", $timestamp_last_month);
date() および time() 関数をいじって、どこに到達するかを確認してください。