How to set local timezone in Sails.js or Express.js How to set local timezone in Sails.js or Express.js express express

How to set local timezone in Sails.js or Express.js


The way I handled the problem after hours of research :

Put process.env.TZ = 'UTC'; //whatever timezone you want

in config/bootstrap.js


I solved the problem, you should setting the MySql options file to change timezone to UTCin the config/connections.jssetting at this

devMysqlServer: {    adapter: 'sails-mysql',    host: '127.0.0.1',    user: 'root',    password: '***',    database: '**',    timezone: 'utc'  },


Trying to solve your problem by setting the timezone on your server is a bit short-sighted. What if you move? Or someone in a different country accesses your application? The important thing is that the timestamps in your database have a timezone encoded in them, so that you can translate to the correct time on the front end. That is, if you do:

new Date('2014-07-06T15:00:00.000Z')

in your browser console, you should see it display the correct date and time for wherever you are. Sails automatically encodes this timestamp for you with the default updatedAt and createdAt fields; just make sure you always use a timezone when saving any custom timestamps to the database, and you should be fine!