javascriptdatemomentjsdate-manipulation

Convert MM/DD/YYYY date to Month Day Year


I'm trying to convert a MM/DD/YYYY date to a long date. So for example, 02/12/2013 would convert to something like Tuesday February 12 2013.

I've looked at MomentJS and other JS methods, but nothing really did what I wanted. Or at least, I didn't think so.

Is there a way to make this date conversion accurately?


Solution

  • Using moment.js,

    You can do it like this with a JavaScript Date object

    var date = new Date(2013, 1, 12);
    console.log(moment(date).format('dddd MMMM D Y'));
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.0/moment.min.js"></script>

    If you want to convert a date string to a long date format string you can do it like this.

    var longDateStr = moment('02/12/2013', 'M/D/Y').format('dddd MMMM D Y');
    console.log(longDateStr);
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.0/moment.min.js"></script>