PHP strtotime () and time zone issue

First look at the definition in the manual

This function expects to accept a string containing the US English date format and try to parse it into a Unix timestamp .

This function will use the  TZ  environment variable (if any) to calculate the timestamp.


Under normal circumstances, the time is obtained based on the time zone of the current computer. If you want to keep the data transferred from the front end to the data stored in the database, you need to adjust the time zone after receiving the data After the result is the same as the front end, then save it in the database

for example:

If the time passed by the front end is $ time = ' 2018-06-08 12:15:30'

If you want to store the data by int type, then you need to use strotime (),

The correct operation should be like this,

date_default_timezone_set('PRC');

$time = strtotime($time);


This is just a way of thinking, and may be handled differently in different business scenarios. The most important thing to remember is that strotime () uses the TZ  environment variable (if any) to calculate the timestamp .


Published 25 original articles · Like2 · Visits 20,000+

Guess you like

Origin blog.csdn.net/longjuanfengzc/article/details/80622842