Home > Back-end >  how convert 13-04-2023 to MMM Do YYYY in javascript?
how convert 13-04-2023 to MMM Do YYYY in javascript?

Time:07-16

I need to convert 13-04-2023 to MMM Do YYYY in javascript

moment(ResData.mDate).format("MMM Do YYYY")

I tried like above. But it gives output as Oct 14th 0018.how I fix this?

CodePudding user response:

This is working:

const o = moment("13-04-2023", "DD-MM-YYYY");
const s = o.format("MMM Do YYYY");
console.log(s); //=> Apr 13th 2023
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>

CodePudding user response:

added the 'DD-MM-YYYY' part so moment correctly identifies the input format and parse the date

const day = '13-04-2023'
const x = moment(day,'DD-MM-YYYY').format("MMM Do YYYY")

console.log(x)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script>

  • Related