Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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");

like image 605
Srikanth Avatar asked May 27 '26 21:05

Srikanth


2 Answers

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

like image 195
Srikanth Avatar answered May 30 '26 09:05

Srikanth


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);
like image 42
David Úbeda Soriano Avatar answered May 30 '26 10:05

David Úbeda Soriano