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

183
Views
The wrong date format in Javascript

I am using luxon library to convert the time:

const DateTime = luxon.DateTime;

console.log(DateTime.local('Sun Jan 23 2003 00:00:00 GMT+0200 (Eastern European Standard Time)').toISODate())
<script src="https://cdn.jsdelivr.net/npm/luxon@2.3.1/build/global/luxon.min.js"></script>

I expect to get this format: 2003-04-23
Why i get null and how to get the expected format using luxon?

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

0

You have the date format wrong, Luxon’s format that belongs in .local is year?, month, day, hour, minute, second, millisecond

Example:

const DateTime = luxon.DateTime;

console.log(
DateTime.local(2003, 1, 23, 17, 36) .toISODate())
<script src="https://cdn.jsdelivr.net/npm/luxon@2.3.1/build/global/luxon.min.js"></script>

For your case you can use the code below to get what you are looking for.

const DateTime = luxon.DateTime;
const date = new Date("Sun Jan 23 2003 00:00:00 GMT+0200 (Eastern European Standard Time)")
const dat = DateTime.fromJSDate(date)
console.log(dat.toFormat('MM-dd-yyyy'))
<script src="https://cdn.jsdelivr.net/npm/luxon@2.3.1/build/global/luxon.min.js"></script>

about 4 years ago · Juan Pablo Isaza Report

0

can be done with pure date

var date =new Date("Sun Jan 23 2003 00:00:00 GMT+0200 (Eastern European Standard Time)")
const DateTime = luxon.DateTime;
var dat = DateTime.fromJSDate(date)
console.log(dat.toString().split("T")[0])
<script src="https://cdn.jsdelivr.net/npm/luxon@2.3.1/build/global/luxon.min.js"></script>

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!