Is there a way in Moment.js to accept both 12-hour and 24-hour times in an input filed.
For example
var myField= $('#myField').val();
var validTime = moment(myField, [h:mm A]).format(HHmm);
I would like to accept:
I can't find any documentation on parsing multiple formats. Perhaps I should test the value using a regex?
I think you simply use an array of formats.
https://momentjs.com/docs/#/parsing/string-formats/
var validTime = moment(myField, ["h:mm A", "H:mm"]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.