简体   繁体   中英

PHP strtotime result is diffent in php7.3.2 and php7.3.1

just less than 1900,more than is normal. php version is 7 example:

date_default_timezone_set('PRC');
$sbegintime = strtotime('1900-01-01 00:00:00');
var_dump($sbegintime);exit;

php7.3:-2209017600
php7.2:-2209017943
why?

Demo ~ https://3v4l.org/MHvIs

The famous SO question relating to a historical event in China wherein the clocks were set back 352 seconds on New Years Day, 1928, meaning you can get unexpected results when dealing with dates before that time. Apparantly PHP has updated the timezone offset for that timezone (for pre 1928 dates), from +8:00 to +8:05 . ( Some other change that I can't find right now, but is mentioned in the linked question, accounts for the offset changing from 352 to 343 ).

/* php7.2 (+8:00) */

(new DateTime('1900-01-01 00:00:00', new DateTimezone("PRC")))->format(\DateTime::ATOM); 
// 1900-01-01T00:00:00+08:00"

/* php7.3: (+8:05) */

(new DateTime('1900-01-01 00:00:00', new DateTimezone("PRC")))->format(\DateTimeInterface::ATOM);
// "1900-01-01T00:00:00+08:05"

The php7.3 changes don't call out this change specifically, but if you look at the changes to php7.2.12 it says

"Upgraded timelib to 2017.08."

and for 7.3.8 it says

"Updated timelib to 2018.02."

Since timelib is the underlying library supporting PHP DateTime, a change implemented between those versions would be resposible, unfortunately I can't find a changelog.

this notes from php strtotime documentation could help you.

The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 UTC to Tue, 19 Jan 2038 03:14:07 UTC. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.)

Prior to PHP 5.1.0, not all platforms support negative timestamps, therefore your date range may be limited to no earlier than the Unix epoch. This means that eg dates prior to Jan 1, 1970 will not work on Windows, some Linux distributions, and a few other operating systems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM