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
3
votes
1 answer

How can I export a plugin from dayjs() in Javascript?

I am using the plugin isToday() to extend the functionality of dayjs() but I don't know how to export isToday() so I can use it in other files. import isToday from "dayjs/plugin/isToday"; export dayjs.extend(isToday);
3
votes
2 answers

Have the difference between two date in days and months with dayjs and React

I have a little problem with logic, I would like to be able to automatically calculate the difference in days and or months between two dates, ex: there are 20 days left, there is 1 month and 17 days left, ... function that does this directly with…
Atl31
  • 165
  • 9
3
votes
1 answer

How to mock dayjs timezone

I have a function that translates a date in format 2021-06-07T07:28:55.69725+00:00 into string of hours and minutes in format 07:28 export function getTime(dateTime: string) { return dayjs(dateTime).format("HH:mm"); } Currently I'm locating in…
Дарья
  • 147
  • 1
  • 12
3
votes
2 answers

TS2339: Property 'dayjs' does not exist on type 'Cypress & EventEmitter

I've recently refactored my code to use dayJS rather than Moment.js, and now Webstorm is reporting a ton of TS2339 errors. These errors aren't preventing my code from compiling or running, but it is making it extremely hard to find actual errors.…
Zachary Costa
  • 106
  • 1
  • 4
3
votes
3 answers

Mocking dayjs extend

In my code that needs testing I use import dayjs from 'dayjs'; import utc from 'dayjs/plugin/utc'; dayjs.extend(utc); dayjs().add(15, 'minute') In my test I need to mock dayjs in order to always have the same date when comparing snapshots in jest…
ver.i
  • 526
  • 1
  • 5
  • 13
3
votes
2 answers

Dayjs: unable to format custom 24hr time to 12hr

import dayjs from "dayjs"; import customParseFormat from "dayjs/plugin/customParseFormat"; dayjs.extend(customParseFormat); when executing something like this "dayjs().format('18:00', "hh:mm A");" , it does not convert to 12 hr timing.... returns…
ashwin1014
  • 351
  • 1
  • 5
  • 18
3
votes
2 answers

How to group item of array by time with step

I have an array like this: let arr = [ { title: 'Some title', start: '09:30:59', end: '09:33:59', }, { title: 'Some title', start: '09:33:59', end: '09:35:59', }, { title: 'Some title', start: '09:35:59', …
Andriy Yushko
  • 395
  • 5
  • 21
3
votes
2 answers

Format custom date using dayjs

I'm working on migrating from momentjs to dayjs How to format a custom date format into a standard one using dayjs. For e.g., I'm trying to format a date in YYYY-MM-DD+h:mm format to YYYY-MM-DD. dayjs gives me an NaN Works perfectly fine with moment…
SubSul
  • 2,523
  • 1
  • 17
  • 27
2
votes
1 answer

How to resolve TypeScript error "Type 'Dayjs' is missing properties from type 'Date'" when using Day.js with Material-UI DatePicker?

I'm trying to use Day.js with Material-UI's DatePicker component in my React project. However, when I set the minDate and maxDate properties to Day.js objects, I get a TypeScript error: Type 'Dayjs' is missing the following properties from type…
Dawid
  • 477
  • 3
  • 14
2
votes
1 answer

DayJS - Strict parsing dates returning false for every attempt with timezones

I'm migrating my old code from momentJS for the dayJS. isValidTimestampDateTime: function (date) { const datetimeFormats = [ "YYYY-MM-DDTHH:mm:ssZ", // 2023-03-01T15:41:00+01:00 "YYYY-MM-DDTHH:mm:ss.SSSZ", //…
Maykel Esser
  • 289
  • 3
  • 15
2
votes
1 answer

Antd + Dayjs: TypeError: clone.weekday is not a function

I upgraded the Ant Design version from 4 to 5 and replaced Moment with Day.js, then encountered this error. const { field, fieldState: { error }, } = useController({ name: name, control: control }); return (
2
votes
0 answers

How to display date string in given timezone using dayjs?

The time is given in YYYY-MM-DDTHH:mm:ssZ format, for example 2023-04-30T16:00:00-05:00. And I want to display 2023-04-30 04:00 PM EST using dayjs. How can I do that?
Ever Dev
  • 1,882
  • 2
  • 14
  • 34
2
votes
0 answers

dayJs - TypeError: date.isBefore is not a function

I am doing this following code for a project where I am getting date in "YYYY-MM-DD" format and passing that into the defaultValue. But getting the above error for which I can't find a solution.
2
votes
1 answer

how to set default value in a input type datetime local field when using dayjs?

I want to set a default date in my input date field but its not working. const [defaultDateFrom, setDefaultDateFrom] = useState(null); const dd = new Date(currentYear, currentMonth, currentDay, 10); const d = dayjs(dd).add(1,…
reacter777
  • 67
  • 4
2
votes
2 answers

How to prevent date conversion to local time zone with DayJS

I have a date string const someDate = 2023-02-13T09:00:00.000-05:00 The problem is when I'm formatting it via DayJS. dayjs(someDate).format('h:mm A') It returns me string according to my local time zone, when I need to keep like I received. Any way…
Alex
  • 455
  • 1
  • 5
  • 14
1 2
3
18 19