简体   繁体   中英

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

@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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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