简体   繁体   English

moment.js格式化多个时区中的当前日期时间

[英]moment.js format current datetime in multiple timezones

I need Pacific time US & Canada in my javascript code. 我的JavaScript代码中需要太平洋时间美国和加拿大。 I am using below line of code for that 我正在使用下面的代码行

moment(new Date()).zone("-07:00").format('hh:mm A')

but if daylight is on then static -07:00 will give incorrect output 但是如果日光开启,那么静态-07:00将提供错误的输出

How to get current server time in JavaScript using moment.js? 如何使用moment.js在JavaScript中获取当前服务器时间?

You dont state what canadian time zone you want, but moment.js's timezone add on is likely what you need. 您没有说明想要的加拿大时区,但是可能需要使用moment.js的timezone With that you can do something like the below which has internal support for DST and not DST: 这样,您可以执行以下操作,该操作具有对DST(而非DST)的内部支持:

 var pacific = moment.tz("US/Pacific"); var canada = pacific.clone().tz("Canada/Eastern"); console.log(pacific.format('hh:mm A')); console.log(canada.format('hh:mm A')); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.4.1/moment-timezone-with-data-2010-2020.min.js"></script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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