PHP strtotime returning false for UTC time

前端 未结 2 1485
闹比i
闹比i 2021-01-28 15:03

My colleague and I are obtaining different results from some unit tests that use strtotime.

The discrepancy originates in this line:

$value = strtotime(         


        
2条回答
  •  礼貌的吻别
    2021-01-28 15:45

    This is because he is on 32-bit and you are on 64-bit machine. See what echo PHP_INT_MAX; returns on both machines. More read here.

    If you wish to get timestamp on 32-bit machine, you can use DateTime as:

    $value = new DateTime('2050-05-01T20:10:29.410Z');
    echo $value->format('U');  // returns 2535048629 as string
    

    or format inputed timestamp as:

    $value = new DateTime('@2535048629');
    echo $value->format('r'); // Sun, 01 May 2050 20:10:29 +0000
    

    instead of date('r', '2535048629'); which will not work on 32-bit machine.

提交回复
热议问题