Questions tagged [dayjs]

Day.js is an immutable date library for JavaScript

Day.js is a minimalist JavaScript library that parses, validates, manipulates, and displays dates and times for modern browsers with a largely Moment.js-compatible API.

https://github.com/iamkun/dayjs

Stack Snippet Starter Pack

(from day.js.org)

HTML

<script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"></script>

JavaScript

console.log(dayjs().format())

Useful links

281 questions
16
votes
3 answers

TypeError: (0 , dayjs_1.default) is not a function

This is my logger.ts file that error happens there: import logger from "pino"; import dayjs from "dayjs"; const log = logger({ prettyPrint: true, base: { pid: false, }, timestamp: () => `,"time":"${dayjs().format()}"`, }); export…
Hasani
  • 3,543
  • 14
  • 65
  • 125
13
votes
2 answers

How can I format time to a dayjs object?

I have the following code import dayjs from 'dayjs' const abc = dayjs("09:00:00") console.log(abc) abc in console is how can I make this into a valid date, the condition being the input is always going to be in format "09:00:00"
Vikrant Bhat
  • 2,117
  • 2
  • 14
  • 32
12
votes
3 answers

dayjs diff between two date in day and hours

I wanna calculate the difference between the two dates with dayjs library. it works nice but I need to something different a little bit. For example: `${dayjs(item).diff(now, 'day') day}` this function returns '20 days' or whatever. but there are…
Ömer Doğan
  • 501
  • 1
  • 6
  • 21
11
votes
4 answers

how to properly use dayjs inside vue 3 app and component

I am able to use dayjs inside vue3 component by adding it to data() import dayjs from 'dayjs' export default { data() { return { dayjs } } } Then I will be able to use it inside template but is this the correct way to do? What if…
Anurat Chapanond
  • 2,837
  • 3
  • 18
  • 31
11
votes
1 answer

Dayjs format with timezone abbreviation i.e. 'z' like in moment.js

Trying to migrate from Moment.js to Dayjs but the only thing I can't get working is the Timezone abbreviation. dayjs('2020-07-06T14:30:00.000-04:00').tz(dayjs.tz.guess()).format('Do MMM YYYY [at] HH:MMa z') Calling the above I would expect 6th Jul…
Labithiotis
  • 3,519
  • 7
  • 27
  • 47
9
votes
1 answer

Dayjs: Any workaround for format duration in h m

I am using dayjs library's duration object for duration format. dayjs.duration(1500, 'minutes').format('H[h] m[m]') // returns 1h 0m Seems the library converts the 24hrs to 1 day and puts the remaining 1 hour in hours. Actually, I want the output…
Vaibhav D
  • 605
  • 9
  • 12
9
votes
1 answer

dayjs() telling me invalid date for this date string

DayJs Using it on the browser if that matters (firefox + Vue + typescript). This is my date string 2021-02-05 12:00 AM It fusses about the AM/PM in my code: const dateObj: any = dayjs('2021-02-05 12:00 AM').format('YYYY-MM-DD hh:mm A'); The…
Dan
  • 1,163
  • 3
  • 14
  • 28
9
votes
2 answers

day.js is not converting UTC to local time

I am running into an issue trying to convert momentjs over to day.js. In moment, I converted utc to local time via moment.utc('2020-04-22T14:56:09.388842').local().format('MM/DD/YY h:mm A') which returns 04/22/20 9:56 AM. When I convert with day.js…
rolu
  • 378
  • 2
  • 3
  • 19
8
votes
5 answers

How to mock dayjs chained methods

I have this dayjs objects: const today = dayjs.utc(date).startOf("day") I am trying to mock it using jest but to no avail. Here is the approach I tried: jest.mock("dayjs", () => ({ extend: jest.fn(), utc: jest.fn((...args) => { const dayjs =…
atomNULL
  • 209
  • 1
  • 2
  • 6
7
votes
2 answers

Using dayjs in my Angular 14 application causes optimization bailout warnings

I'm quite new to Angular and within our project, we switched recently to Angular 14.2.12. We use moment.js for time based calculation and date time parsing. But after switching to Angular 14, we got optimization bailout warnigs because of…
Thomas
  • 81
  • 3
7
votes
4 answers

dayjs() is in the wrong timezone

Problem Calling dayjs() results in a date that is correct except it is off by two hours. For some reason, dayjs() seems to be set to the wrong time zone (GMT), when my actual time zone is GMT+2. Expected Mon, 09 Aug 2021 17:45:55 GMT+2 Actual Mon,…
Robert Schauer
  • 91
  • 1
  • 1
  • 4
7
votes
4 answers

Difference between two time using dayjs

I have two inputs of time and I want to get the difference/time-interval between these two using dayjs fromtime = '13:00' totime = '17:00' So the output for the above two should be 4:00 hours I tried console.log( …
beingyogi
  • 1,316
  • 2
  • 13
  • 25
7
votes
5 answers

how to get locale dynamically from dayjs https://www.npmjs.com/package/dayjs?

When I use like dayjs(date).locale('te').format('YYYY MMM DD'), then I get Month value in english. For working with locale, I have to import locale. import * as locale from 'dayjs/locale/te'; The problem is that I don't see a way to dynamically…
mayank goyal
  • 87
  • 1
  • 1
  • 6
6
votes
2 answers

dayjs does not parse British English dates correctly

I'm experimenting with dayjs. Following the example in the documentation, I have set this in my HTML script:
magnol
  • 344
  • 3
  • 15
6
votes
6 answers

dayjs is not converting timezones properly

I'm trying to convert a date from my local time (Taipei UTC+8) to Los Angeles ( UTC-7) however dayjs conversion seems to be completely off : dayjs("2020-09-21 20:30").tz("Asia/Taipei") this results in Tue Sep 22 2020 05:30:00 GMT-0400 (Eastern…
João Pedro
  • 794
  • 2
  • 12
  • 28
1
2 3
18 19