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
2
votes
0 answers

Add date to date list with weekday logic in Day.js?

I'm using Day.js library. I have a list of working days, every day from 10am to 6pm. Furthermore, I want to insert the appointment date into the list and add it to the duration. but if that sum exceeds 6pm, the next day, the remainder should…
Alexa
  • 33
  • 7
2
votes
1 answer

Localized format without the day

Is there any way to get a localized format in DayJS plugin but without the day? I need to show in a calendar the month and year only but depending on the locale, the month can be on the first place or at the end. I've checked in the docs…
Proz1g
  • 1,177
  • 4
  • 16
  • 36
2
votes
3 answers

Simplfying JavaScript

I'm currently a web developer boot camp student and I am working on a project. I know there is a way to simplify this function but I can't seem to grasp it. What is the way to simplify this entire thing into a for loop so I don't have to do this to…
joonkidk
  • 31
  • 4
2
votes
2 answers

Is there a way to run dayjs tests on desired time zone locally?

So here is the problem. I am migrating from moment to dayjs. There is a lot of code covered with tests, where dayjs is used. Some of them I would like to make run on specific time zone. With moment I was using moment-timezone library. in some test…
Tigran Petrosyan
  • 524
  • 4
  • 14
2
votes
1 answer

Change dayjs locale in Nuxt3

I cannot change dayjs language display when I change the language. in plugin/dayjs.js import dayjs from 'dayjs' import relativeTime from 'dayjs/plugin/relativeTime.js' import utc from 'dayjs/plugin/utc.js' import timezone from…
Unknows
  • 21
  • 3
2
votes
1 answer

How do I use dayjs in Vite for Vue or React?

If you attempt to import dayjs into a Vue/React app using Vite you will find it fails. Vite only works with ESM modules.
mbokil
  • 3,202
  • 30
  • 22
2
votes
0 answers

Set global dayJs locale at Nuxt SSR

This only doesn't work when rendered server side! I've got the problem, that dayJs doesn't update the locale globally after loading a page. While i18n works fine, dayJs doesn't update there. In fact it switches to the locale for 1 second but then…
bibamann
  • 2,469
  • 1
  • 11
  • 9
2
votes
1 answer

showing date/time from MongoDB as X minutes/hrs/seconds ago

I am getting dates from 2 different API endpoints and saving them to MongoDB using Mongoose (used date in the schema). Here is an example of the 2 dates in the database. Using dayjs, one of them works correctly and the other one shows in 2 hours…
Waterfall
  • 584
  • 1
  • 5
  • 15
2
votes
1 answer

Can i extends Dayjs class?

I'm using Dayjs, typescript. I want to use like this export class CustomDate extends dayjs.Dayjs { format() { } } It returns 'TypeError: Class extends value undefined is not a constructor or null'. When I searched this, the reason occured this…
higuy
  • 41
  • 7
2
votes
0 answers

use dayjs to parse a date without a year

I would like to use day.js to parse a date string that does not include a year. In Node.js (and Chrome, I am told), it successfully parses the string as a date but sets the year to 2001. dayjs('06-05'); // 2001-06-06T07:00:00.000Z dayjs('6/5'); …
Graham Charles
  • 9,394
  • 3
  • 26
  • 41
2
votes
2 answers

Days between dates in DayJS UK Format

Im using dayjs, and I'm trying to calculate the days between 2 days so that I can output Today, Tomorrow and X days time The problem I'm having though seems to be with the date formats const date1 = dayjs('31/10/2021'); const date2 =…
K20GH
  • 6,032
  • 20
  • 78
  • 118
2
votes
0 answers

dayjs(date).format gives wrong day for one input vs other input

For an input date of “23-SEP-2021 00:00” we're getting output of September 22, 2021, but for “17-SEP-2021 00:00:00" it returns September 17, 2021. Code looks like this: export const formatDate = (date) => { return dayjs(date).format('MMMM DD,…
Michele
  • 3,617
  • 12
  • 47
  • 81
2
votes
1 answer

Momentjs is not converting certain Spanish months to UTC

I am working on a React Native application which is available on two languages (English & Spanish). Getting date in English is fine but for Spanish, Momentjs is not able to convert it to moment object for certain months(in spanish) like Abril, It…
Dev AKS
  • 512
  • 1
  • 5
  • 17
2
votes
0 answers

Overriding a single Locale property in dayjs()

We allow users to change their preferred locale in our web application. I set the dayjs() locale using a variable like this: var localeAbbr = '@server_generated_abbr'; dayjs.locale(localeAbbr); However, we also let them choose their preferred first…
Jason Butera
  • 2,376
  • 3
  • 29
  • 46
2
votes
1 answer

How to use updateLocale in nuxtjs/dayjs?

I would like to change the short weekdays for the dutch locale (nl). To do that I would need to use updateLocale, as described here: https://day.js.org/docs/en/customization/weekday-abbreviations. This is what I currently have in nuxt.config.js: …
Sacred Agent
  • 53
  • 1
  • 6