0

次のコードはなぜですか

$first_day = strtotime('first day of this month', '2012-06-01');
echo $first_day;

結果が返されませんか?文字列は空です。

4

3 に答える 3

1

これを試して :

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

?>
于 2013-03-01T08:54:17.833 に答える
1

あなたが言うように、strtotime関数内の指定された2番目のパラメーターがタイムスタンプではないため、応答がありませんでした。

したがって、最初にタイムスタンプに変換します。

以下のコードを参照してください:

$first_day = strtotime('first day of this month', strtotime('2012-06-01'));
于 2013-03-01T09:11:41.823 に答える
0

以下のように使用してください。

$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()

于 2013-03-01T08:54:37.300 に答える