Convert 12 hour (AM/PM) string to 24 Date object using moment js
var today = new Date();
let options = {
hour: "2-digit", minute: "2-digit"
};
console.log(today.toLocaleTimeString("en-us", options));
Just a little conversation "2 PM" to "14.00"
const number = moment("02:00 PM", ["h:mm A"]).format("HH:mm");
console.log(number); // Output = "14.00"
"14.00" to "2 PM"
const number = moment("14.00", ["HH:mm"]).format("hh:mm a");
console.log(number); // Output = "02:00 pm"
See documentation of moment js parse
function
JSFiddle
var dt = moment("12:15 AM", ["h:mm A"]).format("HH:mm");
I know that this answer is not for the question (actually it is for the opposite case), but I will put it for completeness and if someone (like me) was looking for it.
In case you want to convert from the 24 Hour system
to 12 Hour system
then you could use the following
return moment("13", ["HH"]).format("hh A");
the previous code will produce the result 1 PM