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

前端 未结 3 1597
甜味超标
甜味超标 2020-12-10 11:56

I have a date given to me by a server in unix time: 1458619200000

NOTE: the other questions you have marked as \"duplicate\" don\'t show how to get there fro

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-10 12:10

    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"
    

提交回复
热议问题