LoginSignup
0
0

More than 3 years have passed since last update.

PHPのdate関数にいろんなものを突っ込んでみた

Posted at

PHPのdate関数にいろんなものを突っ込んだ時のテスト
日付が1日足りない場合の時の挙動なんかおもしろいかも。

echo $birth . ':' . date('Y/m/d H:i:s', strtotime($birth));    //:1970/01/01 09:00:00

日付形式に変換できないものは「1970/01/01 09:00:00」になるみたいです。


    $birth = null;
    echo $birth . ':' . date('Y/m/d', strtotime($birth));    //:1970/01/01

    $birth = '';
    echo $birth . ':' . date('Y/m/d', strtotime($birth));    //:1970/01/01

    $birth = 'あああ';
    echo $birth . ':' . date('Y/m/d', strtotime($birth));    //1999/99/99:1970/01/01

    $birth = '1999/99/99';
    echo $birth . ':' . date('Y/m/d', strtotime($birth));    //1999/99/99:1970/01/01

    $birth = '1999/00/00';
    echo $birth . ':' . date('Y/m/d', strtotime($birth));    //1999/00/00:1998/11/30

    $birth = '0000/00/00';
    echo $birth . ':' . date('Y/m/d', strtotime($birth));    //0000/00/00:-0001/11/30

    $birth = '1999/01/01';
    echo $birth . ':' . date('Y/m/d', strtotime($birth));    //1999/01/01:1999/01/01

[/php]


0000の場合は日付がずれるみたいです
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0