dtrotfd1012 2014-08-26 17:04
浏览 98
已采纳

PHP和Python显示不同的时间

I have a Python application that stores the local time into a mySQL database and a PHP application that displays that date/time through a Web interface. I'm observing a constant offset (from GMT) of the displayed date/time.

I can find nothing in the PHP / Python documentation to explain this difference.

The Python application stores the local time:

import time
localTime = int(time.time())

The PHP application then retrieves the time and displays it:

 date('n/j/y H:i:s', $bg['last_polled'])

where $bg retrieves the entry from the mySQL database.

Why don't these two agree on what localtime is (both applications are running on same server)

  • 写回答

3条回答 默认 最新

  • douwei7501 2014-08-26 20:49
    关注

    As noted above, the timezone needs to be explicitly set. Ideally in a php.ini file. As a practical matter, I found at least two instances of php.ini and decided to take the coward's way out and add the following to startup.php:

    date_default_timezone_set('America/Louisville');
    

    The timezones for the US are far from intuitive (and largely depricated. I see a lot of entries to cover Indiana when parts of the state ignored DST)

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

报告相同问题?

悬赏问题

  • ¥15 BV260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序