Home > Article > Web Front-end > What are the methods for sequelize time zone configuration in Node.js?
This article mainly introduces you to the configuration method of sequelize time zone in Node.js. The article first briefly introduces the basic concept of time zone, and then introduces the configuration method of sequelize time zone in detail through sample code. Friends who need it You can use it as a reference, and follow the editor to learn together.
Basic Concepts
Let’s first introduce some basic concepts that we may have learned in geography class.
Speaking of which, time is really a magical thing. In the past, people determined the time by observing the position of the sun (for example, using a sundial), which caused the time to be different in areas with different longitudes and latitudes. Later, people further stipulated that with the meridian as the center and extending to the east and west sides, a time zone was divided every 15 degrees, which was exactly 24 time zones. Then, because there are 24 hours in a day, the earth rotates 360 degrees once, and 360 degrees / 24 hours = 15 degrees / hour, so every time zone difference is one hour.
The first standard time (time at the center of the meridian) is the standard time of the Royal Greenwich Observatory in London, England (because it happens to be where the prime meridian passes). This is what we often call GMT. (Greenwich Mean Time). Then each other time zone determines its own time according to the standard time. The time zone in the east is later (expressed as GMT hh:mm), and the time zone in the west is earlier (expressed as GMT-hh:mm). For example, China Standard Time is East Eighth District, and our time is always 8 hours later than GMT time. They are at 1 am, and ours is already 9 am.
However, GMT is actually calculated based on the rotation and revolution of the earth (the time when the sun passes the Royal Greenwich Observatory in London, England every day is 12 noon), which is not very accurate, so later a standard time calculated based on the atomic clock was proposed UTC (Coordinated Universal Time).
Generally, GMT and UTC are interchangeable, but in fact, GMT is a time zone, while UTC is a time standard.
Start the text of this article below:
Node.js sequelize time zone configuration
sequelize By default, when saving the date It will be converted to 00:00 time zone, for example
Submit data:
time=2017-07-17 16:52:12
will be saved in the database as
2017-07-17 08:52:12
Solution:
Configure time zone when sequelize
timezone: ' 08:00'
For example:
const sequelize = new Sequelize(config.database, config.username, config.password, { host: config.host, port: config.port, dialect: 'mysql', pool: { max: 5, min: 0, idle: 10000 }, timezone: '+08:00' });
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
How to use form-data format to transfer files in NodeJs
How to configure the interface proxy using vue-cli
About folder structure configuration in vue
About how to implement a single page skeleton screen in Vue
The above is the detailed content of What are the methods for sequelize time zone configuration in Node.js?. For more information, please follow other related articles on the PHP Chinese website!