简体   繁体   中英

Display the times for local time (Los Angeles or Pacific) and New York with JavaScript?

I have a question for my homework.

If I were to display timezones from different timezone locations, how do you insert JavaScript to display the times for local time (Los Angeles or Pacific) and New York?

Your best bet is not to implement it by hand in any way but to use a ready library. Use Moment Timezone

var now = moment(); // current timestamp, using your machine's time zone
var nowLA = now.tz('America/Los_Angeles'); // converted to LA time zone
var nowNY = now.tz('America/New_York'); // converted to NY time zone

Then, you can print it using any of the formats provided by Moment , eg.

now.format('MMMM Do YYYY, h:mm:ss a');  // September 13th 2015, 10:43:17 am

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