Home > Backend Development > PHP Tutorial > php中把美国时间转为北京时间的自定义函数分享_php实例

php中把美国时间转为北京时间的自定义函数分享_php实例

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 20:39:18
Original
980 people have browsed it

由于最近做邮件系统用到了时间转化,需要把从谷歌gmail下载下来的邮件时间转化为北京时间,于是乎就写了一个时间转化函数,希望对有需要的盆友所有启迪,我们都知道中美时间相差13个小时,下面直接上代码:

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);
}
}
Copy after login

另一种+8小时的算法:

$bj_time = date ("Y-m-d H:i:s" , mktime(gmdate('H')+8,gmdate('i'),gmdate('s'),gmdate('m'),gmdate('d'),gmdate('Y')));
Copy after login
Related labels:
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