Keshav Agrawal Keshav Agrawal - 5 months ago 21
Javascript Question

Trying to implement momentjs to display localtime

Before asking this question I have searched all stackoverflow and read the docs but I can't just understand how to convert one UTC date to local time of an user and display it in his format. I keep trying different methods but I keep getting the same time again and again.

so my django returns obj.created_on in UTC as - 2013-12-26T13:52:24 - no timezone Info here but I know its UTC

Now I want momentjs to auto detect the user's timezone and convert it in that timezone.

Can I have proper syntax for the same?

I was trying this as well:

new_date = moment(obj.created_on).utc().local().format()

Answer

Moment has two different utc functions:

So, you want this syntax:

moment.utc(obj.created_on).local().format()