Answers for "convert 12 hour format to 24 hour format in javascript"

1

javascript conver time into 24 hour format

var dt = moment("12:15 AM", ["h:mm A"]).format("HH:mm");
Posted by: Guest on July-17-2020
1

convert 12 hour format to 24 hour format in javascript

const convertTime12to24 = (time12h) => {
  const [time, modifier] = time12h.split(' ');

  let [hours, minutes] = time.split(':');

  if (hours === '12') {
    hours = '00';
  }

  if (modifier === 'PM') {
    hours = parseInt(hours, 10) + 12;
  }

  return `${hours}:${minutes}`;
}
Posted by: Guest on April-18-2021

Code answers related to "convert 12 hour format to 24 hour format in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language