在php中设置时区

编程入门 行业动态 更新时间:2024-10-26 05:30:05
本文介绍了在php中设置时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

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.0 和 DateTimezone>= 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 12:47:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1395129.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时区   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!