4

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

Phil
  • 157,677
  • 23
  • 242
  • 245
  • @RonvanderHeijden put test.php and visist in chrome – user13839505 Jun 30 '20 at 09:36
  • 1
    Heed the warning on https://www.php.net/manual/en/timezones.others.php and try with Asia/Shanghai instead, does that change anything? – deceze Jun 30 '20 at 09:46
  • 1
    @deceze nothing changes – user13839505 Jun 30 '20 at 09:51
  • 2
    Nothing in the [release notes](https://www.php.net/ChangeLog-7.php#7.3.2) indicates a change in this area. (The behavior changes in [7.3.2](https://3v4l.org/Ionr7)). Looks like it has something to do with [the timezone](https://3v4l.org/MlN92). Same results for [Asia/Shanghai](https://3v4l.org/GBK0a). – John Conde Jul 01 '20 at 01:56
  • Does this answer your question? [Why is subtracting these two times (in 1927) giving a strange result?](https://stackoverflow.com/questions/6841333/why-is-subtracting-these-two-times-in-1927-giving-a-strange-result) – chiliNUT Jul 01 '20 at 04:00

2 Answers2

3

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.

chiliNUT
  • 18,989
  • 14
  • 66
  • 106
-3

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 e.g. dates prior to Jan 1, 1970 will not work on Windows, some Linux distributions, and a few other operating systems.