To ignore user’s time zone and force Date() use specific time zone with JavaScript, we can use the moment timezone library.
To install it, we run
npm install moment-timezone --save
Then we write
const moment = require("moment-timezone");
const d = moment(1270544790922)
.tz("Europe/London")
.format("YYYY-MM-DD HH:mm:ss");
to call moment
with a timestamp in milliseconds.
And we set the time zone of the datetime with the tz
method.
Then we call format
to return a datetime string with the value returned by tz
.