Srikanth
Srikanth

Reputation: 339

TypeError: dayjs(...).tz is not a function

I am getting this error.

TypeError: dayjs(...).tz is not a function

My code is

const dayjs = require('dayjs');

const dayjsAmerica = dayjs("2014-06-01 12:00").tz("America/New_York");

Upvotes: 8

Views: 5342

Answers (2)

Srikanth
Srikanth

Reputation: 339

You need to extend the dayjs class with the utc and timezone classes/plugins:

const dayjs = require('dayjs');
const utc = require('dayjs/plugin/utc');
const timezone = require('dayjs/plugin/timezone');
dayjs.extend(utc);
dayjs.extend(timezone);

Refer to docs for more details: https://day.js.org/docs/en/timezone/timezone

Upvotes: 3

this worked also for me as @kandula

npm install dayjs

const dayjs = require('dayjs');

const utc = require('dayjs/plugin/utc');

const timezone = require('dayjs/plugin/timezone');

dayjs.extend(utc); dayjs.extend(timezone);

Upvotes: 0

Related Questions