dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

How to install utc & timezone plugin?

Open The-LukeZ opened this issue 10 months ago • 2 comments

I don't know how to install specific plugins.

The docs only provide an answer on how to use them, but not on how to install them. I want to use timezone and utc e.g.

Image

The-LukeZ avatar Mar 13 '25 13:03 The-LukeZ

// YARN
yarn add dayjs

// NPM
npm i dayjs

After that you just import and extend

import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';

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

dayjs.tz.setDefault('Asia/Tokyo');

dayjs.utc().format('YYYY-MM-DD HH:mm:ssZ');

thadeucity avatar Mar 15 '25 03:03 thadeucity

aight, I will try it out. But I did install dayjs with npm install dayjs and the plugins were not found.

The-LukeZ avatar Mar 15 '25 23:03 The-LukeZ

This works:

import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc.js';
import timezone from 'dayjs/plugin/timezone.js';

(note the .js)

slootjes avatar Jun 19 '25 14:06 slootjes

I reinstalled dayjs completely which made it work eventually.

The-LukeZ avatar Jul 02 '25 07:07 The-LukeZ