Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

moment-timezone: unix timestamps with timezones

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
like image 463
suellen Avatar asked Sep 18 '25 02:09

suellen


1 Answers

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.

like image 156
Matt Johnson-Pint Avatar answered Sep 20 '25 17:09

Matt Johnson-Pint