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

Sharing the custom function to convert American time to Beijing time in PHP, Beijing time in the United States_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:22:07952browse

Sharing the custom function to convert US time to Beijing time in php, US Beijing time

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')));

PHP Custom Function Optional Attributes

Give it a default value
For example: function check($aa,$bb=0){ }
The latter is optional

The space is in the United States, and the displayed time is in the United States. How to adjust it back to Beijing time

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/851346.htmlTechArticleSharing the custom function to convert the United States time to Beijing time in php. The United States Beijing time is used in the mail system recently. When the time comes to convert, when you need to download the emails from Google gmail...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn