admin管理员组

文章数量:1309921

I can't parse the simplest date string for some reason. the following is giving me 'invalid date'.

 moment.locale('en-gb');
 var tempDate = moment("23/07/2018").format("DD/MM/YYYY");

this doesn't work either:

 moment.locale('en-gb');
 var tempDate = moment("23/07/2018");

I can't parse the simplest date string for some reason. the following is giving me 'invalid date'.

 moment.locale('en-gb');
 var tempDate = moment("23/07/2018").format("DD/MM/YYYY");

this doesn't work either:

 moment.locale('en-gb');
 var tempDate = moment("23/07/2018");
Share Improve this question asked Jul 13, 2018 at 10:20 BMillsBMills 9012 gold badges10 silver badges27 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

You can use String+Format version of the moment function:

moment("23/07/2018", "DD/MM/YYYY")

var mydate= moment("23/07/2018","DD/MM/YYYY").format("DD/MM/YYYY");
console.log(mydate);
<script src="https://cdnjs.cloudflare./ajax/libs/moment.js/2.22.2/moment.min.js"></script>

本文标签: javascriptParsing datestring in format quotddmmyyyyquot in momentjsStack Overflow