问题
This happens using dateTimePicker and moment.js:
If I use this line code:
console.info($('#inp_date_time_'+value.fila+'_id').val());
print this date format:
04/09/2015 08:31
then If I use this line code:
moment($('#inp_date_time_'+value.fila+'_id').val()).format('YYYY-DD-MM HH:mm:ss');
print this date format:
2015-09-04 08:31:00
and it's ok, but If I select a day more bigger that 12 (example : 13/09/2015)
I have "invalid date" , I think that take the days like months , or I don't know.
How can I fix this?, sorry my english.
回答1:
Better option would be to specify dateFormat
when creating a moment
object. So replace moment($('#inp_date_time_'+value.fila+'_id').val()).format('YYYY-DD-MM HH:mm:ss');
with moment($('#inp_date_time_'+value.fila+'_id').val(),, 'DD/MM/YYYY HH:mm').format('YYYY-DD-MM HH:mm:ss')
;
来源:https://stackoverflow.com/questions/33503910/invalid-date-using-moment-javascript-and-datetimepicker