Moment.js 如何在客户端将 UTC 时间转换为本地时间

How Moment.js can convert UTC time to local time at client side

先看代码

$(document).ready(function() {
  $("[data-utc-time]").text(function () {
    var utcTime = $(this).attr("data-utc-time");
    return moment.utc(utcTime, 'DD.MM.YYYY HH:mm').local().format('DD.MM.YYYY HH:mm');
});

特地看到这一行moment.utc(utcTime, 'DD.MM.YYYY HH:mm').local().format('DD.MM.YYYY HH:mm');

我想知道 Moment 库将 UTC 时间转换为本地时间的依据是什么?

如何时刻知道客户来自哪个时区地区?

可以在上面遮光。谢谢

在客户端是运行,从而了解客户端的本地时间。在内部它使用 JavaScript Date 对象来实现它,它具有本地时间行为。