moment.utc(date) 和 moment(date).utc() 之间的区别
Difference between moment.utc(date) and moment(date).utc()
试图了解以下行为和区别:
moment.utc(date) and moment(date).utc()
使用“2018-05-31”作为参数:
moment.utc('2018-05-31').format()
将给出:
2018-05-31T00:00:00Z
而 moment('2018-05-31').utc().format()
将给出:
2018-05-31T04:00:00Z
我都在 EST 时区执行。
第一个 moment.utc(String)
将您的字符串解析为 UTC,而后者 将您的 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()
.
This brings us to an interesting feature of Moment.js. UTC mode.
请参阅 Local vs UTC vs Offset 指南以了解有关 UTC 模式和本地模式的更多信息。
console.log( moment.utc('2018-05-31').format() );
console.log( moment('2018-05-31').utc().format() );
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.min.js"></script>
试图了解以下行为和区别:
moment.utc(date) and moment(date).utc()
使用“2018-05-31”作为参数:
moment.utc('2018-05-31').format()
将给出:
2018-05-31T00:00:00Z
而 moment('2018-05-31').utc().format()
将给出:
2018-05-31T04:00:00Z
我都在 EST 时区执行。
第一个 moment.utc(String)
将您的字符串解析为 UTC,而后者 将您的 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 ofmoment()
.This brings us to an interesting feature of Moment.js. UTC mode.
请参阅 Local vs UTC vs Offset 指南以了解有关 UTC 模式和本地模式的更多信息。
console.log( moment.utc('2018-05-31').format() );
console.log( moment('2018-05-31').utc().format() );
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.min.js"></script>