Mongodb节省了一天的时间-时区问题 [英] Mongodb saves one day less - Time Zone Issue

查看:443
本文介绍了Mongodb节省了一天的时间-时区问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以角度格式将日期发布为MM/DD/YYYY,但是当它保存在Mongodb中时,它会以少一天的时间保存ISO()格式.我正在使用MEAN堆栈进行开发.

I post date in the format from angular as MM/DD/YYYY but but when it saves in Mongodb it saves the ISO() format with one day less. I am developing using MEAN stack.

例如:(来自角度)10/03/2016 mongodb:ISODate("2016-10-02T18:30:00.000Z")

eg :(from angular ) 10/03/2016 mongodb : ISODate("2016-10-02T18:30:00.000Z")

我想解决时区问题,同时将日期保存在mongodb中.

I would like to resolve the timezone issue while saving the date in mongodb .

推荐答案

MongoDB将日期时间保存为UTC.因此,在保存之前,它已从IST更改为UTC. IST与UTC的偏移量是+05:30.因此,您的日期时间10/03/2016 00:00:00可以追溯到2016-10-02T18:30:00.000Z(UTC的同一日期时间).

The MongoDB saves date time in UTC. So, it changes from IST to UTC before saving. IST offset is +05:30 from UTC. So your date time 10/03/2016 00:00:00 goes back 2016-10-02T18:30:00.000Z, the same date time in UTC.

从MongoDb获取数据之前,您必须将时间设置回IST,然后再呈现给客户端.

You have to set the time back to IST while fetching the data from MongoDb before presenting to the client.

首先,您应该尝试从一开始就将日期时间保存为ISO格式.

Btw you should try and save the datetime in ISO format from the beginning.

在MongoDB文档页面上有关日期

More here on the MongoDB doc page for Date

这篇关于Mongodb节省了一天的时间-时区问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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