To fix UTC gives wrong date with moment.js and JavaScript, we should add the time zone to the datetime string we’re parsing into a moment object.
For instance, we write
const datetime = moment(new Date("07-18-2022 UTC"))
.utc()
.format("YYYY-MM-DD HH:mm");
to call moment with the new Date("07-18-2022 UTC") date, which we specified to be UTC.
Then we call utc to return a UTC moment.
Next, we call format to return a datetime string in specified format.