Search code examples
javascriptnode.jsluxon

Luxon produces invalid dates


I have this date:

const fromDate = "Sat Oct 01 2022 00:00:00 GMT+0300 (GMT+04:00)";

I want to change it to be in a specific timezone, this is how I tried:

const newDate = DateTime.fromJSDate(fromDate).setZone("Asia/Amman").toJSDate()

I also tried:

const newDate = DateTime.fromJSDate(fromDate, { zone: "Asia/Amman" }).toJSDate()

But both ways are producing invalid dates!

Invalid Date

ISO fromDate also failed.

So, what is going on here?


Solution

  • Just wrapping fromDate with new Date() fixes the problem. Since the function expects a date object; not a string.