0
为什么我的时区与我的时区中的原始日期时间不同?带时区的PHP时间戳
ex。我在8/9/17 8:30:51运行代码。
其结果将是17年4月10日11:30:51
$now = new DateTime();
now->setTimezone(new DateTimeZone('Asia/Manila'));
echo $now->format("m/d/y G.i:s<br>");
为什么我的时区与我的时区中的原始日期时间不同?带时区的PHP时间戳
ex。我在8/9/17 8:30:51运行代码。
其结果将是17年4月10日11:30:51
$now = new DateTime();
now->setTimezone(new DateTimeZone('Asia/Manila'));
echo $now->format("m/d/y G.i:s<br>");
这很简单,它被设置为通用时间区的日期,在你的Web服务器和大多数的浏览器。
$now = new DateTime();
$now->setTimezone(new DateTimeZone("Asia/Manila"));
echo $now->format("m/d/y G.i:s<br>");
因此,您使用此代码来参数化您的日期。
DateTimeZone - >要你的时区,我预测它是亚洲/马尼拉
格式 - >格式日期所需的格式。
如果它不工作,试试这个:
在本地服务器上,您可以在PHP_INI更改配置。
在您的文件寻找:
;定义日期函数使用的默认时区
; http://php.net/date.timezone
date.timezone = UTC
变化为
;定义日期函数使用的默认时区
; http://php.net/date.timezone
date.timezone =亚洲/马尼拉
如果这没有解决您的问题。在所有PHP文件的开头使用这个。
date_default_timezone_set("Asia/Manila");
setlocale(LC_ALL, 'your_language');
例:
date_default_timezone_set("America/Sao_Paulo");
setlocale(LC_ALL, 'pt_BR');
如果你喜欢,给出分数还是很有帮助的标志。
你的服务器处于什么时区? –
@JoseMarques在我的桌面上我正在使用UTC canada – questioner
我在谈论你使用哪个Web服务器?例如Apache,Windows ISS。 –