In php, convert the U.S. time to the custom function of Beijing Time. Beijing time _ PHP Tutorial

Source: Internet
Author: User
Tags time zones
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.