2

I am trying to initialize time of los_angles time zone in moment. But it is throwing the following error:

Moment Timezone has no data for 2018-08-08T10:00:00

Following is my code:

moment().tz("2018-08-08T10:00:00","YYYY-MM-DDTHH:mm:ss",true,"America/Los_Angeles").format("YYYY-MM-DDTHH:mm:ss");
MGupta
  • 75
  • 2
  • 9

3 Answers3

6

You are supposed to remove () at moment from moment().tz(..). The correct one is moment.tz(..) as in

moment.tz("2018-08-08T10:00:00","YYYY-MM-DDTHH:mm:ss",true,"America/Los_Angeles").format("YYYY-MM-DDTHH:mm:ss");

it gives me result

"2018-08-08T10:00:00"

Ref: http://momentjs.com/timezone/

deerawan
  • 8,002
  • 5
  • 42
  • 51
0

Can you try this:

moment.tz("2018-08-08T10:00:00","YYYY-MM-DDTHH:mm:ss",true,"America/Los_Angeles").format("YYYY-MM-DDTHH:mm:ss");

Sriman Pathy
  • 189
  • 1
  • 6
0

I got a very similar error (Moment Timezone has no data for 1624031790031) and solved it by 3 steps:

  1. Import "moment-timezone", not "moment".

const momentTimezone = require("moment-timezone");

  1. Load the moment timezone data.

You can add time zones one at a time:

momentTimezone.tz.add('America/Los_Angeles|PST PDT|80 70|0101|1Lzm0 1zb0 Op0');

Or you can add them as an array:

momentTimezone.tz.add([
"America/Los_Angeles|PST PDT|80 70|0101|1Lzm0 1zb0 Op0",
"America/Port_of_Spain|LMT AST|46.4 40|01|-2kNvR.U|43e3"
]);

I saved an abbreviated version (only the time zones I needed) of the following time zone data into a JSON file

https://github.com/moment/moment-timezone/blob/develop/data/packed/latest.json

then added those time zones to moment-timezone:

const momentTimezoneData = require("../utils/momentTimezoneData"); momentTimezone.tz.add(momentTimezoneData.zones);

  1. Make sure your time zone is one you've loaded. Apparently our timezone had not; it had been a unix timestamp 1624031790031. After making it one of the time zones (e.g. "America/Chicago") we'd loaded in #2 above, it all worked.
const timeInTheZone = momentTimezone
  .tz("2021-06-24T04:34:36.380Z", "America/Chicago")
  .format('YYYY-MM-DD HH:mm');
David
  • 895
  • 8
  • 12