Home > Enterprise >  How to change json date to MM/DD/YY using moment?
How to change json date to MM/DD/YY using moment?

Time:06-02

Lets say I have this date

const date = '2022-05-24T14:52:30.250Z';

how would I use moment to check if this is a valid date and convert it to something like 05/24/22? Thank you for any help and guidance!

CodePudding user response:

const date = '2022-05-24T14:52:30.250Z';
if (moment(date).isValid()) console.log(moment(date).format("MM/DD/YY")
  • Related