Invalid date using moment javascript and DateTimeP

2019-09-09 11:06发布

This happens using dateTimePicker and moment.js:

enter image description here

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.

enter image description here

How can I fix this?, sorry my english.

1条回答
迷人小祖宗
2楼-- · 2019-09-09 11:56

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');

查看更多
登录 后发表回答