Home > Backend Development > PHP Tutorial > php实现的太平洋时间和北京时间互转的自定义函数分享_php实例

php实现的太平洋时间和北京时间互转的自定义函数分享_php实例

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 20:38:20
Original
1119 people have browsed it

没有什么好说的了,直接上代码吧:

/**

 * 太平洋时间转北京时间

 */

public function pacificToPRC($time=''){

 date_default_timezone_set('Pacific/Apia');

 if(empty($time)){

 $time = time();

 }

 date_default_timezone_set('Asia/Shanghai');

 $date = date('Y-m-d H:i:s',$time);

 $time = strtotime($date);

 return $time;

}
/**

 * 北京时间转太平洋时间

 * @param unknown_type $time

 */

public function PRCToPacific($time=''){

 if(empty($time)){

 date_default_timezone_set('Asia/Shanghai');

 $time = time();

 }

 date_default_timezone_set('Pacific/Apia');

 $date = date('Y-m-d H:i:s',$time);

 $time = strtotime($date);

 return $time;

}
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template