duanqian2278 2014-01-12 09:31
浏览 144
已采纳

使用date_default_timezone_set后,时区不会更改

I'm setting my default time zone for my page using:

date_default_timezone_set("America/Los_Angeles");

I have to set it there, because my server doesn't allow me to alter the php.ini file or .htaccess. The problem is, when I use this:

NOW()

to send the current time to my database, it still send it as the UTC timezone.

What I'm trying to do is display comments users display from a comment box on the page, and it's showing the time for each of the comments in the wrong timezone now.

  • 写回答

2条回答 默认 最新

  • duanjiwang2927 2014-01-12 10:08
    关注

    date_default_timezone_set is a PHP function. It can only affect the behaviour of PHP.

    NOW() is a database function, and changing your timezone in PHP has no effect on it. NOW() returns in the format YYYY-MM-DD HH:MM:SS.

    time() is the equivalent PHP function. time() returns simply the number of seconds since the Unix Epoch. To get output in the same format as NOW(), use date("Y-m-d H-i-s");. This automatically uses time() underneath to get the current system time.

    Read more:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序