search
Homephp教程php手册php中把美国时间转为北京时间的自定义函数分享,美国北京时间

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

由于最近做邮件系统用到了时间转化,需要把从谷歌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);
}
}

另一种+8小时的算法:

$bj_time = date ("Y-m-d H:i:s" , mktime(gmdate('H')+8,gmdate('i'),gmdate('s'),gmdate('m'),gmdate('d'),gmdate('Y')));

PHP 自定义函数 选填 属性

给他个默认值
例如:function check($aa,$bb=0){ }
后者就为选填了
 

空间用美国的,显示时间是美国的怎调回北京时间

如果你有服务器的控制权就将服务器的时间调整一下
PHP的我晓得
1.如果你用的软件可以设置时区,那么请通过软件设置。譬如DZ, phpWind, vBulletin等都有此功能。

2.如果你的软件不可以设置时区,你可以通过修改空间的 .htaccess文件

打开你的 .htaccess文件,加入这一样文字

代码:

SetEnv TZ location

location根据你要的不同地区设置,全部时区可以在这里找到 www.php.net/manual/en/timezones.php

譬如你要设置为美国亚特兰大时间,语法写成这样就可以了:

代码:

SetEnv TZ America/Atlanta
 

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.