Invalid date using moment javascript and DateTimePicker

非 Y 不嫁゛ 提交于 2019-12-11 14:12:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!