I want to make restful app in nodejs
Server: centos 7 64x Database: postgresql Additional: express, sequelize Table: datetime with timezone
When I selecting rows with sequelize from database, created_at column gives me wrong time. 5 hour added to datetime.
I change timezone configuration of centos to +5 (Tashkent/Asia) Also change postgresql timezone configuration to +5 Datetime is correct in database when shows.
But when I select it converts to like this
"createdAt": "2018-08-12T17:57:20.508Z"
In database column shows this
2018-08-12 22:57:20.508+05
config.json
"development": {
"username": "postgres",
"password": "postgres",
"database": "zablet",
"host": "127.0.0.1",
"dialect": "postgres",
"timezone": "Tashkent/Ashgabat",
"define": {
"charset": "utf8",
"dialectOptions": {
"collate": "utf8_general_ci"
},
"freezeTableName": true
}
}
index.js
'use strict';
var fs = require('fs');
var path = require('path');
var Sequelize = require('sequelize');
var basename = path.basename(__filename);
var env = process.env.NODE_ENV || 'development';
var config = require('../config/config.json')[env];
var db = {};
if (config.use_env_variable) {
var sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
var sequelize = new Sequelize(config.database, config.username, config.password, config);
}
fs
.readdirSync(__dirname)
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(file => {
var model = sequelize['import'](path.join(__dirname, file));
db[model.name] = model;
});
Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});
db.sequelize = sequelize;
db.Sequelize = Sequelize;
module.exports = db;
updated config.json
{
"development": {
"username": "postgres",
"password": "postgres",
"database": "postgres",
"host": "127.0.0.1",
"dialect": "postgres",
"define": {
"charset": "utf8",
"dialectOptions": {
"collate": "utf8_general_ci"
},
"freezeTableName": true
},
"dialectOptions": {
"useUTC": false
},
"timezone": "+05:00"
}
}
How can I select rows from database in correct timezone format?