简体   繁体   English

如何将特定时区的UTC日期转换为UTC +0(默认格林威治)?

[英]How to convert UTC date of specific timezone to UTC +0 (default Greenwich)?

I want to insert an item to the DB in a specific date based on the client's timezone. 我想根据客户的时区在特定日期将一个项目插入数据库。 So if client desired in today on 20:00, and his timezone is +3, I want that node and mongodb will set the date to be on today on 17:00. 因此,如果客户希望今天在20:00时,并且他的时区是+3,我希望该节点和mongodb将日期设置为今天的17:00。 I hope that is clear enough. 我希望这很清楚。

Generally it is recommended to save all timestamps in database in UTC only, along with it you can save extra field timezone/offset value in each document. 通常,建议仅将所有时间戳保存在UTC中,并且可以在每个文档中保存额外的字段时区/偏移值。 Check - https://docs.mongodb.com/manual/tutorial/model-time-data/ 检查-https: //docs.mongodb.com/manual/tutorial/model-time-data/

But if you want to save in local timezone, you need to do conversion at application level before inserting in database. 但是,如果要保存在本地时区,则需要在应用程序级别进行转换,然后再插入数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM