dqce48404 2013-07-03 23:32
浏览 80
已采纳

错误的时区MongoDate在PHP中

I inserted data in MongoDB via PHP and one field is a date. So, according to the MongoDB documentation, I used a new MongoDate() to do that.

In MongoDB, The date is stored such as ISODate("2013-07-03T22:56:12Z"). That means my timezone is Z (= 0Z), so the timezone is equal to 0.
But I am in the US West coast and the timezone for my location is 8Z (Pacific Time).

When I type new Date() on Mongo in the terminal, everythin g is OK. The date is ISODate("2013-07-03T22:56:128Z"), so this is the correct timezone 8Z.

My development environment is Windows and MongoDB is version 2.4.4

Is there something to setup in MongoDB, in the PHP code or in the php.ini to avoid this error?

  • 写回答

3条回答 默认 最新

  • dongqiancui9194 2013-07-04 00:46
    关注

    Your database dates should be in UTC; PHP should then adjust accordingly - usually with date_default_timezone_set. Afterwards, you can take the date from the database and plug it into gmdate("y-m-d", strtotime($date)) for example.

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

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突