简体   繁体   English

使用 moment.js 获取不同时区的当前时间

[英]getting current time in different time zone using moment.js

I am trying to figure out how to get current time in different time zones but below method does not return anything我想弄清楚如何在不同的时区获取当前时间,但下面的方法不返回任何内容

var timeUpdate = setInterval(function () {
    var currentTime = moment().format()
    var GMT_current_time = currentTime.tz("Europe/London").format("HH:mm DD MMM");
$("#GMT_display_time").text(GMT_current_time);  
}, 1000);    

The output of the format function is a string. format函数的输出是一个字符串。 The tz function works on a moment object. tz函数作用于矩对象。

moment().tz("Europe/London")

以格式返回当前时间。

moment.tz(moment(), 'Asia/Karachi').format('DD/MM/YYYY HH:mm')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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