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?
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>
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>