Nodejs,mongodb different time zone issues

Source: Internet
Author: User
Tags time zones mongodb

Problem: Different countries, the use of different time zones, and server code in the country, across time zone date, based on the date query, no data query

The 1.mongodb stored new date () is the UTC time, which is the time of the 0 time zone, world standard Time

2. Refer to Moment official website, time zone problem:

npm install moment-timezone

var moment = require (' Moment-timezone ');
Console.log (Moment (' 2018-08-17t07:46:37.000+08:00 '). TZ ("Asia/tokyo"). Format (' Yyyy/mm/dd HH:mm:ss '))//asia/tokyo , Asia/hong_kong,america/new_york,asia/shanghai
Console.log (' Shanghai: ' +moment (). TZ ("Asia/shanghai"). Format (' Yyyy/mm/dd HH:mm:ss ')
Console.log (' Hong Kong: ' +moment (). TZ ("Asia/shanghai"). Format (' Yyyy/mm/dd HH:mm:ss ')
Console.log (' Japan: ' +moment (). TZ ("Asia/tokyo"). Format (' Yyyy/mm/dd HH:mm:ss ')
Console.log (' New York: ' +moment (). TZ ("America/new_york"). Format (' Yyyy/mm/dd HH:mm:ss ')

For more supported time zones, please refer to Moment-timezone source Moment-timezone/builds/moment-timezone-with-data-2012-2022.js

Nodejs,mongodb different time zone issues

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.