Reputation: 5451
I'd like to insert a MySQL date using NodeJS but it doesn't work.
My new date : 1989-12-31 00:00:00
After the NodeJS insert : 1989-12-30 23:00:00
NodeJS inserting :
var user = request.body.user;
user.birth = user.birth.year + '-' + user.birth.month + '-' + user.birth.day + ' 00:00:00';
this.userDao.save(user);
Result of new Date()
using Javascript :
Thu Dec 08 2016 11:00:15 GMT+0100 (Paris, Madrid)
If I add one hour of the inserting date it works.
Upvotes: 0
Views: 1489
Reputation: 27609
You need to set the options.timezone
in Sequelize, otherwise it will use the timezone offset of the database server, which in your case seems to be GMT, or one hour offset from Paris.
[options.timezone='+00:00']
The timezone used when converting a date from the database into a JavaScript date. The timezone is also used to SET TIMEZONE when connecting to the server, to ensure that the result of NOW, CURRENT_TIMESTAMP and other time related functions have in the right timezone. For best cross platform performance use the format +/-HH:MM. Will also accept string versions of timezones used by moment.js (e.g. 'America/Los_Angeles'); this is useful to capture daylight savings time changes.
Sequelize connection
const sequelize = new Sequelize(db, user, pass, { timezone: 'Europe/Paris' });
Upvotes: 3