I use the codeigniter framework to build a website, and use date ('Y-m-d h: I: s') to get the time and store it in the database. But today I found that, the storage time has a lot of time difference with my local storage.
Because the time zone is incorrect and the time in China is inconsistent, there are two solutions:
(1) Modify PHP. ini
[Date]; defines the default timezone used by the date functions; http://php.net/date.timezonedate.timezone = PRC
Restart Apache after modification.
(2) Use date_default_timezone_set ("Asia/Shanghai") before using date ")
The following parameters can be set in China. The specific classification method is to be investigated.
{"CST", 0, 28800, "Asia/Chongqing" },{ "CST", 0, 28800, "Asia/Chungking" },{ "CST", 0, 28800, "Asia/Harbin" },{ "CST", 0, 28800, "Asia/Kashgar" },{ "CST", 0, 28800, "Asia/Macao" },{ "CST", 0, 28800, "Asia/Macau" },{ "CST", 0, 28800, "Asia/Shanghai "}, {"CST", 0, 28800, "Asia/Taipei" },{ "CST", 0, 28800, "Asia/Urumqi" },{ "CST", 0, 28800, "PRC" },{ "CST", 0, 28800, "ROC "},
However, in codeigniter, after date is used, it is found that the time difference is much better. Therefore, codeigniter must have the time zone configuration.
The following settings are available in the application/config/my_config.php file:
<? PHP date_default_timezone_set ('America/los_angeles ');
Change to date_default_timezone_set ("Asia/Shanghai.