I'm using moment.js in my project, what I want is to convert a date in format dd-mm-yyyy to yyyy-mm-dd. I tried this but it didn't work, it gives me an invalid date:
alert(moment('14/10/2017').format('YYYY/MM/DD'));
You need to specify the current format of your date in moment():
var date = moment('14/10/2017', 'DD/MM/YYYY').format('YYYY/MM/DD');
console.log(date); // 2017/10/14
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.2.1/moment.min.js"></script>
var date = moment('Sat Sep 23 2017 07:04:08 GMT+0100').format('hh:mm');.