在php中设置时区 [英] Setting time zone in php

查看:35
本文介绍了在php中设置时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码来获取服务器时间.但我在孟加拉国,我没有孟加拉国的时间.请告诉我孟加拉国的确切时间我必须在哪里换车.

I'm using the following code to get server time. But I'm in Bangladesh and I don't get Bangladeshi time by this. Please tell me where I have to change for the exact Bangladeshi time.

$Vdate=date("F j, Y, g:i a");

推荐答案

功能 date_default_timezone_set()>= 5.1.0 全局设置时区.

Function date_default_timezone_set()>= 5.1.0 set timezone globally.

如果您需要在本地设置时区,对于特定的变量,您可以使用 DateTime>= 5.2.0DateTimezone>= 5.2.0 类,like:

If you need to set timezone locally, for specific variable, you can use DateTime>= 5.2.0 and DateTimezone>= 5.2.0 classes, like:

$dt = new DateTime('now', new DateTimezone('Asia/Dhaka'));
echo $dt->format('F j, Y, g:i a');

这是 PHP 中的所有可用时区的列表.

由于上述函数均不适用于 PHP 4.x 版,因此您无法设置时区,只能将服务器时间设置为您的时区,或者为 time() 函数,例如:

Since non of the above functions will work on PHP version 4.x, you have no other way to set timezone, rather that setting your server time to your timezone, or add offset to time() functions, like:

echo date('F j, Y, g:i a', time() - 6*3600); # Bangladesh is in UTC+6

这篇关于在php中设置时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆