Maximum time() | PHP

前端 未结 6 1355
半阙折子戏
半阙折子戏 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:30

    DateTime seems to use 32bit on 64bit servers, too. So you get into trouble.

    I've solve it this way:

    new DateTime("99999/12/31 00:00:00");
    

    Because, the date overflows the maximum length for DateTime, date use the maximum possibel value and returns a DateTime-object like this (inspected with var_dump) :

    object(DateTime)#9 (3) { ["date"]=> string(19) "2031-09-12 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Berlin" } }
    

    I'm not sure if it differs with the versions of PHP. I've tested it with version 5.4.

提交回复
热议问题