次のコードはなぜですか
$first_day = strtotime('first day of this month', '2012-06-01');
echo $first_day;
結果が返されませんか?文字列は空です。
これを試して :
phpバージョンが5.3未満の場合
<?php
$d = date_create();
print date_create($d->format('Y-m-1'))->format('Y-m-d')
?>
phpバージョン5.3以降の場合
<?php
$d = new DateTime('2012-06-20');
$d->modify('first day of this month');
echo $d->format('jS, F Y');
?>
ここに別の解決策があります:
<?php
echo date('Y-m-d', strtotime( 'first day of '.date('2012-06-01'))); ///time stamp
echo strtotime(date('Y-m-d', strtotime( 'first day of '.date('2012-06-01')))); // formated date
?>
あなたが言うように、strtotime
関数内の指定された2番目のパラメーターがタイムスタンプではないため、応答がありませんでした。
したがって、最初にタイムスタンプに変換します。
以下のコードを参照してください:
$first_day = strtotime('first day of this month', strtotime('2012-06-01'));
以下のように使用してください。
$first_day = strtotime('2012-06-01');
echo $first_day;
月の最初の日付
<?php
echo strtotime(date('Y-m-d', strtotime( 'first day of '.date('2012-06-01')));
?>
date_parse_from_format()
うまくいかない場合は、代わりに試してくださいstrtotime()