search

Home  >  Q&A  >  body text

php strtotime time zone problem, in some years the UTC time zone and the PRC time zone differ by 9 hours

$timeStr='1987-5-4';
echo '测试时间:'.$timeStr;
echo PHP_EOL;
$prcTime=strtotime($timeStr);
echo 'PRC时间:';
echo $prcTime;
echo PHP_EOL;
date_default_timezone_set('UTC');
$utcTime=strtotime($timeStr);
echo 'UTC时间:';
echo $utcTime;
echo PHP_EOL;
echo 'UTC与PRC时间相差:'.(($utcTime-$prcTime)/3600).'小时';
echo PHP_EOL;

Result:

Test time: 1987-5-4

PRC time:547052400

UTC time: 547084800

UTC and PRC time Difference: 9 hours


After testing, the difference between UTC and PRC time for dates from 1987 to 1991 is 9 hours.

The php version is

PHP 7.1.9 (cli) (built: Aug 30 2017 18:34:46) (ZTS MSVC14 (Visual C 2015) x64)

Copyright (c) 1997-2017 The PHP Group

Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies


刘强刘强2127 days ago1499

reply all(5)I'll reply

  • 刘强

    刘强2019-01-29 10:34:30

    Forgot to ask the question, what is the reason for this? How to deal with this bug?

    reply
    0
  • jesse

    We are in the East Eighth District, and the PHP time starts from District 0, so there will be a difference of eight hours (PS: I didn’t learn geography well in junior high school). The solution: 1. Modify PHP configuration file 2. Use date_default_timezone_set

    jesse · 2019-01-29 13:13:39
    刘强

    Well, there is a difference of 8 hours, but here is the difference between PRC East Eighth District and UTC, which is 9 hours, and it is only part of the year (1987-1991).

    刘强 · 2019-01-31 08:54:36
    唐润

    I also encountered this problem two days ago, and after discussing it in the group, I roughly concluded that it was caused by daylight saving time.

    唐润 · 2020-01-20 09:33:17
  • Cancelreply