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

210
Views
Luxon substracting one day if JS date is UTC

I create a date with Luxon in the following way:

const date = DateTime.utc(2000, 6, 23).toFormat('yyyy-MM-dd')

Then I try to convert it to a JS date by doing this:

const jsDate = new Date(date)

Finally, I convert it back to the 'yyyy-MM-dd' format with

const parsedDate = DateTime.fromJSDate(jsDate).toFormat('yyyy-MM-dd')

But instead of giving me 2000-06-23 it gives me 2000-06-22. Is this a bug on Luxon or I need to do something to get the correct date?

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

0

I try to convert it to a JS date by doing const jsDate = new Date(date)

Uh, why not just date.toJSDate()?

Instead of giving me 2000-06-23, DateTime.fromJSDate(jsDate).toFormat('yyyy-MM-dd') gives me 2000-06-22. Is this a bug on Luxon or I need to do something to get the correct date?

According to its docs, fromJSDate defaults to creating a DateTime instance in the local (system) timezone. If you expect another UTC date back, you need to specify that:

DateTime.fromJSDate(jsDate, {zone: 'utc'}).toFormat('yyyy-MM-dd')
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!