How to set date always to eastern time regardless of user's time zone

You can easily take care of the timezone offset by using the getTimezoneOffset() function in Javascript. For example,

var dt = new Date(1458619200000);
console.log(dt); // Gives Tue Mar 22 2016 09:30:00 GMT+0530 (IST)

dt.setTime(dt.getTime()+dt.getTimezoneOffset()*60*1000);
console.log(dt); // Gives Tue Mar 22 2016 04:00:00 GMT+0530 (IST)

var offset = -300; //Timezone offset for EST in minutes.
var estDate = new Date(dt.getTime() + offset*60*1000);
console.log(estDate); //Gives Mon Mar 21 2016 23:00:00 GMT+0530 (IST)

Though, the locale string represented at the back will not change. The source of this answer is in this post. Hope this helps!


Moment.js (http://momentjs.com/timezone) is your friend.

You want to do something like this:

var d = new Date(1458619200000);
var myTimezone = "America/Toronto";
var myDatetimeFormat= "YYYY-MM-DD hh:mm:ss a z";
var myDatetimeString = moment(d).tz(myTimezone).format(myDatetimeFormat);

console.log(myDatetimeString); // gives me "2016-03-22 12:00:00 am EDT"