javascript - Issue parsing date format M/D/YYYY -
i have string date in format m/d/yyyy
, i'm trying format new date()
date. i've tried following , it's printing out invalid date
.
console.log(date) console.log(moment(date, "mm/dd/yyyy").todate()) console.log(moment(date, "m/d/yyyy").todate()) 3/10/2017 2017-10-03t04:00:00.000z 2017-10-03t04:00:00.000z 3/13/2017 invalid date invalid date
https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js
this parses correctly without throws massive warning.
var date = '2/23/2017'; console.log(moment(date, "mm/dd/yyyy").todate()) console.log(moment(date, "m/d/yyyy").todate()) var date = '3 / 13 / 2017'; console.log(moment(date, "mm/dd/yyyy").todate())
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js"></script>
console.log(moment(date).todate())
you can try moment(date, "mm/dd/yyyy").todate();
Comments
Post a Comment