PHP date()函数未给出正确的时间 [英] PHP date() function not giving correct time

查看:63
本文介绍了PHP date()函数未给出正确的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚为什么php date()给我错误的时间,将实际时间设置为2小时。

I am trying to figure out why php date() is giving me the wrong time, setting the actual time back 2 hours.

<?php echo date("Y-m-d H:i:s"); ?>

这给出了2011-01-01 03:14:04而不是2011-01-01 05: 14:04。该小时减少了2。
我没有更改date()的时区,并且当用户访问该网站时,我也希望其时区的时间正确。

This gives 2011-01-01 03:14:04 instead of 2011-01-01 05:14:04. The hour is decreased by 2. I have not change my timezone for date() and when users visit the site I want the time to be correct for their timezone also. How can I get this to work using php?

推荐答案

这是因为默认情况下它显示GMT时间,您可以更改您所在的地区并使用以下代码

it is because by default it shows GMT time you can change for your region with following code

   date_default_timezone_set("Asia/Bangkok");//set you countary name from below timezone list
    echo $date = date("Y-m-d H:i:s", time());//now it will show "Asia/Bangkok" or your date time

受支持的时区列表
http://www.php.net/manual/en/timezones.php

这篇关于PHP date()函数未给出正确的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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