Kaken
Kaken

Reputation: 163

Moment Timezone, set default time zones

I want to work in same timezone in my web application, I try to use de time zone default function moment.tz.setDefault("Europe/Madrid"); the dates conversions (json format) are bad, substact one day by default

Here is my plunker

http://plnkr.co/edit/xsugHtDLLUfxugCJRwIZ?p=preview

Thanks

 var jsonDate = "/Date(118101600000)/"; // DD/MM/YY = 29/09/1973 

 alert(moment(jsonDate).format("DD/MM/YY")); // conversion ok

 moment.tz.setDefault("Europe/Madrid");

 alert(moment(jsonDate).tz('Europe/Madrid').format("DD/MM/YY")); // substract one day by default 28/09/1973
 alert(moment(jsonDate).format("DD/MM/YY"));                     // substract one day by default 28/09/1973

Upvotes: 0

Views: 4659

Answers (1)

Sajjad Ali Khan
Sajjad Ali Khan

Reputation: 1813

@kaken

Can u check this link

I followed that link to solve timezone issue.

ex: moment(jsonDate).zone("+03:00"); // moment can able to parse JsonDate

To work with named timezones, include Moment Timezone as well and use .tz()

// determines the correct offset for America/Phoenix at the given moment

moment(1369266934311).tz('America/Phoenix').format('YYYY-MM-DD HH:mm')

// always "2013-05-22 16:55"

Upvotes: 1

Related Questions