moment js is returning wrong formatted values for an iso timestamp

后端 未结 2 1771
孤城傲影
孤城傲影 2021-01-16 00:10

I\'m passing \"2018-01-31T22:55:02.907Z\" this timestamp to the moment() function but it returns the wrong value after formatting the date part.

2条回答
  •  醉梦人生
    2021-01-16 00:42

    You have to use moment.utc():

    By default, moment parses and displays in local time.

    If you want to parse or display a moment in UTC, you can use moment.utc() instead of moment().

    console.log(moment("2018-01-31T22:55:02.907Z").format('YYYY-MM-DD'));
    console.log(moment.utc("2018-01-31T22:55:02.907Z").format('YYYY-MM-DD'));

提交回复
热议问题