Moment.js toISOString result is different?

前端 未结 1 983
栀梦
栀梦 2021-01-26 05:49

Is something wrong with code.

var mom = moment("23-11-2016 00:00", "DD-MM-YYYY HH:mm");
alert(mom.toISOString());
//result 2016-11-22T17:00:00         


        
相关标签:
1条回答
  • 2021-01-26 06:46

    As the doc says:

    By default, moment parses and displays in local time.

    while .toISOString() always returns a timestamp in UTC:

    Note that .toISOString() always returns a timestamp in UTC, even if the moment in question is in local mode. This is done to provide consistency with the specification for native JavaScript Date .toISOString(), as outlined in the ES2015 specification.

    You probably have -7 hours offset from UTC.

    Use format() if you want to display date in local time.

    If your input string represents a UTC time, then use moment.utc(String, String);

    0 讨论(0)
提交回复
热议问题