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
-1
votes
5 answers

Insert element between other elements of array if condition is met

Now I have an array like below. const reserveList = [ { name: 'john', start: '2022-09-01' }, { name: 'mark', start: '2022-09-02' }, { name: 'ken', start: '2022-09-03' }, { name: 'sara', start: '2022-09-05' }, ]; and I want to…
tehoo
  • 81
  • 2
  • 9
-1
votes
3 answers

How to convert "dd/mm/yyyy" to ISO string in JavaScript

How can I convert this date: 29/12/2022 where: 29 is day, 12 is month, 2022 is year, to ISO string. I tried this: var dateStr = "29/12/2022"; var parts = dateStr.split("/") var myDate = new Date(parseInt(parts[2]), parseInt(parts[1]) - 1,…
makaMa
  • 11
  • 3
-1
votes
1 answer

How can I check if a date is older then 10 days from today?

Im trying to see if a date is beyond different intervals, and if so add some stylesheet to them. Im using Vuejs version 3 for this. I have not been able to locate the issue, but the result vary. For example if user.active.created_at is the same date…
Adam
  • 1,231
  • 1
  • 13
  • 37
-1
votes
1 answer

dayjs: date supplied from mongodb is at least 5 minutes old

I'm using dayjs and trying to figure out how to check if a date is at least 5 minutes ago. Here is an example of a date: 2021-11-04T12:20:46.485Z Its probably some subtracting and adding 5 somewhere but the MongoDB format and dayjs is somewhat…
-1
votes
1 answer

Showing how long ago a post was made in JavaScript

I would like to show website views when an article was posted i.e, 1 hour ago, 4 ,mins ago, 2 years ago, etc. I would like to use DAY.JS to do the task.

-2
votes
2 answers

How to get hours from an ISO date string?

I have an ISO date which is stored as a string. I want to get only the hours part as is. The below code does not work. So, how do I make it work using dayjs? function getHours(date:string){ const hour : dayjs(date).hour(); …
MasterJoe
  • 2,103
  • 5
  • 32
  • 58
-2
votes
1 answer

how to apply localized format on a date javascript

I want to display a date on the page, and want to show it differently by the language in the browser setting. for example: mm/dd/yyyy (in case of 'en') yyyy/mm/dd(in case of 'ko') currently I use dayjs and it doesn't really help. how to customize…
dfassf
  • 142
  • 10
-2
votes
3 answers

How to convert a date string into hours, minutes and second using DayJS in react?

I am wondering if there is a way to covert this function by using DayJS: const formatHours = (dateStr: string) => { const date = new Date(dateStr); return `${date.getUTCHours()}:${date.getMinutes()}:${date.getSeconds()}`; }
user14749773
  • 143
  • 2
  • 18
-2
votes
1 answer

Determine which Friday of the month the date is

Given a date like April 22, 2022 how can we accurately determine which Friday of that Month it is. In this case it is the 4th Friday. I have tried all combinations of adding the week day (0-6, so 5) plus the current day, dividing things by 7, using…
-2
votes
1 answer

How can I round seconds to 0 with dayJS

I am creating an app which asks the users for 2 dates, then it calculates the time between them dates. But the dates have seconds in them so instead of 90 minutes I am getting 89 minutes. So I can convert this: startTime: Sat Apr 09 2022 09:00:39…
KillianCode
  • 79
  • 2
  • 9
-4
votes
2 answers

How to convert date into my required format using dayjs module

I am reading a date from a locator through cypress the actual date is 11/04/2023 cy.get("#eff-date").invoke('text').then(()=>{ const edate = dayjs(text.split(':')[1].format('DD-MMM-YYYY')) }) What it is returning 04-Nov-2023 But it should be…
1 2 3
18
19