Issue
i am using momentjs.com with nodejs and im trying to get unix timestamps for multiple timezones, but sadly the the output is not correct.
code:
var moment = require('moment-timezone');
var berlin = moment.tz('Europe/Berlin').unix();
var angeles = moment.tz('America/Los_Angeles').unix();
var london = moment.tz('Europe/London').unix();
console.log(berlin);
console.log(angeles);
console.log(london);
output:
1472241731
1472241731
1472241731
Solution
A Unix Timestamp is always UTC based. It is the same timestamp everywhere on the planet simultaneously.
Changing the time zone of a moment
object using moment-timezone only affects the local time value, such as used with the format
function (and others). It does not change the moment in time being represented, and therefore does not change the underlying timestamp.
Answered By - Matt Johnson-Pint Answer Checked By - David Marino (WPSolving Volunteer)