Home > Article > Backend Development > Sharing the custom function to convert American time to Beijing time in PHP, Beijing time in the United States_PHP tutorial
Due to the recent use of time conversion in the email system, it is necessary to convert the email time downloaded from Google Gmail into Beijing time, so I wrote a time conversion function. I hope it can enlighten friends in need. Knowing that the time difference between China and the United States is 13 hours, enter the code directly below:
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')));
Give it a default value
For example: function check($aa,$bb=0){ }
The latter is optional
If you have control over the server, adjust the server time
I know about PHP
1. If the software you are using can set the time zone, then please set it through the software. For example, DZ, phpWind, vBulletin, etc. all have this function.
2. If your software cannot set the time zone, you can open your .htaccess file by modifying the space's .htaccess file
and add this text
code :
SetEnv TZ location
location is set according to the different regions you want. All time zones can be found here www.php.net/manual/en/timezones.php
For example, if you want to set the time in Atlanta, USA, the syntax can be written as follows:
Code:
SetEnv TZ America/Atlanta