Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert date in YYYY/MM/DD format in MomentJS

I am using MomentJS for converting the date format.

I have a date in this format 2010/12/01 and I want to convert it to 01/12/2010 using MomentJS only.

I have another date in this format "12/02/2014" and I want to convert in "2014/12/02"

<!--begin snippet: js hide: false console: true babel: false-->

<!--language: lang-js-->

    var date = moment(new Date(2010/12/01)).format("MMM Do h/mm");
    console.log(date);

<!--language: lang-html-->

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment.min.js"></script>

<!--end snippet-->

How do I convert them using MomentJS

like image 674
Javascript Coder Avatar asked Dec 15 '22 18:12

Javascript Coder


1 Answers

You can try this:

moment('2010/12/01', 'YYYY/MM/DD').format('DD/MM/YYYY')
like image 63
Nerve Avatar answered Dec 27 '22 01:12

Nerve