Maximum time() | PHP

前端 未结 6 1402
半阙折子戏
半阙折子戏 2020-12-15 18:08

It\'s kind of a silly question, but what would be the maximum INT value of a time() and it\'s future date, e.g.

1st January 2999

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-15 18:23

    PHP stores the highest integer number it can represent in the PHP_INT_MAX constant:

    date('Y-m-d H:i:s', PHP_INT_MAX); // 2038-01-19 04:14:07
    

    If you want to work with dates beyond that, consider using the DateTime API, e.g.

    $dt = new DateTime('1st January 2999');
    $dt->add(DateInterval::createFromDateString('+1 day'));
    echo $dt->format('Y-m-d H:i:s'); // 2999-01-02 00:00:00
    echo $dt->format('U');           // 32472226800
    

提交回复
热议问题