0

I need Pacific time US & Canada in my javascript code. 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

How to get current server time in JavaScript using moment.js?

1 Answer 1

3

You dont state what canadian time zone you want, but moment.js's timezone add on is likely what you need. With that you can do something like the below which has internal support for DST and not 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>

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot DelightedD0D appreciated.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.