Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);    
like image 995
Ma Ti Avatar asked Jan 25 '15 00:01

Ma Ti


2 Answers

The output of the format function is a string. The tz function works on a moment object.

moment().tz("Europe/London")
like image 97
Matt Johnson-Pint Avatar answered Nov 10 '22 02:11

Matt Johnson-Pint


Returns current time with format.

moment.tz(moment(), 'Asia/Karachi').format('DD/MM/YYYY HH:mm')
like image 34
Umair Ahmed Avatar answered Nov 10 '22 01:11

Umair Ahmed