简体   繁体   中英

moment.js offset by one day issue

Some of my users report different outputs, offset by one day.

Code:

var call=[1451084400000,1451170800000,1451257200000,1451343600000,1451430000000,1451516400000,1451602800000,1451689200000,1451775600000]

    var arrayLength = call.length;
    for (var i = 0; i < arrayLength; i++) {
    document.getElementById('output').innerHTML += moment(call[i],"x").format("YYYY-MM-DD")+"<br>"
    }

Expected result:

2015-12-26
2015-12-27
2015-12-28
2015-12-29
2015-12-30
2015-12-31
2016-01-01
2016-01-02
2016-01-03

Issue:

2015-12-25
2015-12-26
2015-12-27
2015-12-28
2015-12-29
2015-12-30
2015-12-31
2016-01-01
2016-01-02

Any ideas why?

Try to convert to the desired timezone. For London timezone should be like this:

date.clone().tz("Europe/London");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM