Skip to content Skip to sidebar Skip to footer

Moment.js Displays Wrong Time

I'm using jQuery.countdown and moment.js to create a multiple instance/time zone aware countdown timer. Everything works except the time zone. Throwing in the time zone changes the

Solution 1:

Seems to work fine?

Here is a fiddle logging out both Los Angeles time then New York time for same Moment object.

with the code being simply:

$(function(){
  var finalDate = moment.tz("2014-06-01 12:00", 'America/Los_Angeles');
  console.log(
    finalDate.format("ha z"),
    finalDate.tz('America/New_York').format("ha z"))

  var nextYear = moment.tz("2018-04-21 00:00", "America/Sao_Paulo");
  $('#clock').countdown(nextYear.toDate(), function(event) {
    $(this).html(event.strftime('%D days %H:%M:%S'));
  });
})

Did you check console for any error messages?

Because I saw this at first:

"Moment Timezone has no data for America/Los_Angeles. See http://momentjs.com/timezone/docs/#/data-loading/."

before realizing I had to include the moment-timezone-with-data package instead of the vanilla moment-timezone to get it to work.

http://momentjs.com/timezone/docs/#/data-loading/.

(edited code bin to include a Jquery countdown working example)

Post a Comment for "Moment.js Displays Wrong Time"