I got a very similar error (Moment Timezone has no data for 1624031790031
) and solved it by 3 steps:
- Import "moment-timezone", not "moment".
const momentTimezone = require("moment-timezone");
- 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);
- 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');