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 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决