admin管理员组文章数量:1401657
Is there a way to set the timezone using moment.js or moment-timezone always to reflect 'America/New_York' regardless of where the user is accessing the app from?
I've tried this but the object's timezone is reflective of the browser's timezone and returns America/Los_Angeles.
moment.tz("8/26/2013 4:55 pm", "M/D/YYYY h:mm a", "America/New_York")
Is there a way to set the timezone using moment.js or moment-timezone always to reflect 'America/New_York' regardless of where the user is accessing the app from?
I've tried this but the object's timezone is reflective of the browser's timezone and returns America/Los_Angeles.
moment.tz("8/26/2013 4:55 pm", "M/D/YYYY h:mm a", "America/New_York")
Share
Improve this question
asked Apr 8, 2016 at 18:52
anmanm
1,9273 gold badges19 silver badges30 bronze badges
2
- Your syntax is totally fine here. When I run it, it produces a date with a -4 offset which is correct. When you say 'the object's timezone', what property are you looking at? – Maggie Pint Commented Apr 8, 2016 at 20:27
-
1
Check the debug console. Are you getting an error
"Moment Timezone has no data for America/New_York"
? If so, you don't have the tz data loaded. See here. – Matt Johnson-Pint Commented Apr 8, 2016 at 22:58
2 Answers
Reset to default 5As stated here,
Moment.js docs
you need to include the timezone module and use it like this:
moment("8/26/2013 4:55 pm", "M/D/YYYY h:mm a").tz("America/New_York").format();
To change the default time zone, use moment.tz.setDefault
with a valid time zone:
moment.tz.setDefault("America/New_York");
moment.js documentation
本文标签:
版权声明:本文标题:javascript - how to set the timezone to 'AmericaNew_York' regardless of browser timezone? (moment.js) - Stack Ov 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744273068a2598279.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论