问题描述
1.node层查询列表中,前端处理时间显示没问题
2.node导出excel中,在node层中用js处理时间,差八个小时,因为时区问题
存在时差问题详解
解决方案
1.更改sequelize中的配置,更改后在node层进行js方式处理,显示没有问题,需要注意的是,列表中查询的时间也需要处理
const Sequelize = require('sequelize');
const sequelize = new Sequelize('dbname', 'username', 'password', {
host: 'localhost',
port: '3306',
dialect: 'mysql',
operatorsAliases: false,
dialectOptions: {
charset: 'utf8mb4',
collate: 'utf8mb4_unicode_ci',
supportBigNumbers: true,
bigNumberStrings: true
},
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
timezone: '+08:00' //东八时区
});
2.利用moment插件进行处理
// 下载
npm install moment --save
// 使用
const moment = require('moment');
moment(new Date(time)).utcOffset("+00:00").format('YYYY-MM-DD HH:mm:ss')