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");
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");
Share Improve this question edited Dec 13, 2022 at 5:52 Srikanth asked Dec 13, 2022 at 5:26 SrikanthSrikanth 3391 gold badge3 silver badges10 bronze badges 1-
You can tick
Answer your own question – share your knowledge, Q&A-style
when posting this. – wei Commented Dec 13, 2022 at 5:30
2 Answers
Reset to default 3You 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/docs/en/timezone/timezone
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);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744801600a4594524.html
评论列表(0条)