javascript 使用 moment.js 获取不同时区的当前时间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28131746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 08:28:14 来源:igfitidea点击:
getting current time in different time zone using moment.js
提问by Ma Ti
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);
回答by Matt Johnson-Pint
The output of the format
function is a string. The tz
function works on a moment object.
该format
函数的输出是一个字符串。该tz
函数适用于矩对象。
moment().tz("Europe/London")
回答by Umair Ahmed
Returns current time with format.
以格式返回当前时间。
moment.tz(moment(), 'Asia/Karachi').format('DD/MM/YYYY HH:mm')