Reputation: 2379
Following date formatting is not working in momentJs
var date ="01-12-2015";//DD-MM-YYY
console.info(moment(date).format('YYYY-MM-DD'));
How can I solve this?
Upvotes: 0
Views: 1446
Reputation: 752
Try this..
var date ="01-12-2015";//DD-MM-YYY
date = date.replace(/-/g,"/")
console.info(moment(new Date(date)).format('YYYY-MM-DD'));
Upvotes: 0
Reputation: 3816
You need to tell momentJS how to parse the string you are giving:
var date ="01-12-2015";//DD-MM-YYYY
console.info(moment(date, 'DD-MM-YYYY').format('YYYY-MM-DD'));
Deprecation warning: moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release. Please refer to https://github.com/moment/moment/issues/1407 for more info.
Upvotes: 3