javascript - TypeError: dayjs(...).tz is not a function - Stack Overflow

I am getting this error.TypeError: dayjs(...).tz is not a functionMy code isconst dayjs = require(&#

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
Add a ment  | 

2 Answers 2

Reset to default 3

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/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

相关推荐

  • javascript - TypeError: dayjs(...).tz is not a function - Stack Overflow

    I am getting this error.TypeError: dayjs(...).tz is not a functionMy code isconst dayjs = require(&#

    2天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信