In php, the user-defined function of converting the U.S. time to Beijing time is shared. In php, the user-defined function of converting the U.S. time to Beijing time is shared. due to the time conversion used by the recent email system in Beijing time, we need to share the custom function of converting us time to Beijing time in php when we download emails from Google gmail.
Since the email system recently used time conversion, it was necessary to convert the email time downloaded from Google gmail to Beijing time, so I wrote a time conversion function, we hope to enlighten all those who need it. we all know that the time difference between China and the US is 13 hours. The following code is directly used:
function datezhuanhuan($dateparams){$ccc=strtotime($dateparams);$date=date(‘Y-m-d');$bjtime=date(‘Y-m-d',$ccc);if($date==$bjtime){$sbjtime=date(‘Y-m-d H:i:s',$ccc);echo substr($sbjtime,11,5);}else{$sbjtime=date(‘Y-m-d H:i:s',$ccc);return substr($sbjtime,5,5);}}
Another 8-hour algorithm:
$bj_time = date ("Y-m-d H:i:s" , mktime(gmdate('H')+8,gmdate('i'),gmdate('s'),gmdate('m'),gmdate('d'),gmdate('Y')));
PHP custom function optional attribute
Give him a default value
Example: function check ($ aa, $ bb = 0 ){}
The latter is optional.
The space in the United States shows how the time was transferred back to Beijing.
If you have control over the server, adjust the server time.
Php I know
1. if the software you use can set the time zone, use the software. Such as DZ, phpWind, and vBulletin.
2. if your software cannot set the time zone, you can modify the. htaccess file of the space.
Open your. htaccess file and add the same text
Code:
SetEnv TZ location
Location is set according to the region you want. for all the time zones, you can find www.php.net/manual/en/timezones.php.
For example, if you want to set the time to Atlanta, the syntax is as follows:
Code:
SetEnv TZ America/Atlanta
Because the email system recently used time conversion, you need to download emails from Google gmail...