javascript - moment.js add month but bad format -
i'm using moment.js manipulate dates. have value stored in field, value et add 1 month. here code:
var mydate = $('#crueventmodal #rdvstartdate').val(); alert('date get:' + mydate); // get: 25-05-2016 mydate = moment(mydate).format("dd-mm-yyyy"); alert('date transformed:' + mydate); // get: nan-nan-0nan var new_date = moment(mydate, "dd-mm-yyyy").add('months', 1); alert('end date: ' + new_date); // get: -62164630800000
but result: 25-06-2016
help please?
format
used format momentjs date, not specify how parse it. if want parse string date specific format, should use moment(string, format)
. have at documentation here.
var mydate = "25-05-2016"; console.log('date get: ' + mydate); mydate = moment(mydate, "dd-mm-yyyy"); console.log('date transformed: ' + mydate); var new_date = moment(mydate, "dd-mm-yyyy").add(1, 'months'); // 'months' should come // after 1 latest // versions. console.log('end date: ' + new_date); console.log('end date (human readable): ' + new_date.format("dd-mm-yyyy"));
<script src="https://cdn.jsdelivr.net/momentjs/2.13.0/moment.min.js"></script>
Comments
Post a Comment