javascriptmomentjs

How to convert this "string" to a correct date?


Struggling to display a date in javascript that is retrieved from a postgres database and returned via python.

When I simply console.log the variable I get back from my GET request, it is in this format:

Thu, 12 Sep 2024 00:00:00 GMT

I'm simply attempting to display that as:

09/12/24

(I don't know where the 00:00:00 GMT portion is coming from, but essentially I just want to discard that. It seems to be affecting my conversions for some reason.)

I AM using moment.js, but have not been able to get it to display the correct date. It always displays 1 day prior (9/11/24).

What would be the easiest method to simply display that returned datetime string as "09/12/24" (the time portion will never need to be accounted for)?


Solution

  • I took the recommendation of the collective to remove momentjs as a dependency, and am now using dayjs instead.

    Being almost a direct drop-in replacement, the solution was minimal with dayjs:

    let s = dayjs(req.req_start, 'ddd, DD MMM YYYY HH:mm:ss')
    s = s.format('MM/DD/YY')