Friday 5 May 2017

nodejs/moment - timezone different between dev/server

We are currently having some issues making momentjs convert to time zones. When on a local Windows computer set to EST, everything works as expected. When switching to the Ubuntu test server, the date is offset by the utcOffset hours. Changing the timezone on the Ubuntu box had no visible effect.

We are calling

router.get("/report/date", (req, res) => {
    var delayInfo = {
        sendDate: moment().format("YYYY-MM-DD"),
        sendTime: moment().format("HH:mm"),
        repeatDuration: 0,
        repeatType: 0,
        sendTimeZone: "Canada/Eastern"
    };

    var _sendDate = null;
    if (delayInfo.sendDate !== null) {
        _sendDate = moment.tz(delayInfo.sendDate + " " + delayInfo.sendTime, "YYYY-MM-DD HH:mm", delayInfo.sendTimeZone);
    }
    res.status(200).send(_sendDate);
});

On the development machine, we get the expected:

"2017-05-05T20:24:00.000Z"

On the Ubuntu/Linux machine, we get

"2017-05-06T00:25:00.000Z" 

Node: 7.9.0 Moment: 2.17.1

Thanks in advance



via Trevor Watson

No comments:

Post a Comment