Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
Dayjs and plain date objects give different difference

At this link of the Dayjs library you will read this:

const date1 = dayjs('2019-01-25')
const date2 = dayjs('2018-06-05')
date1.diff(date2) // 20214000000 default milliseconds

But if you type in the console, you'll get this:

new Date(2019,0,25) - new Date(2018,5,5)
// result: 20221200000

Why the difference?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

const dayjs = require("dayjs")

const date1 = dayjs("2019-01-25")
const date2 = dayjs("2018-06-05")
console.log(date1.diff(date2)) // 20214000000

console.log(new Date(2019, 0, 25) - new Date(2018, 5, 5)) // 20214000000
console.log(new Date(2019, 0, 25).getTime() - new Date(2018, 5, 5).getTime()) // 20214000000

You can get the timestamp of Date with the .getTime() function, and in this case you are just doing 1548381600000 - 1528167600000. I'm not sure how did you get 20221200000 but this value is just wrong.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!