1

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?

Anders
  • 8,307
  • 9
  • 56
  • 88
Jose Sosa
  • 27
  • 1
  • 2

1 Answers1

0

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
Adam Michalik
  • 9,678
  • 13
  • 71
  • 102