Answers for "24 hours time picker with seconds using javascript"

2

javascript get 24 hour time

var date = new Date();
console.log(date.toLocaleString('en-GB'));
Posted by: Guest on November-08-2020
36

12 hours to 24 hours javascript

const time = '5:00AM';

function convertTo24HrsFormat(time) {
   const slicedTime = time.split(/(PM|AM)/gm)[0];

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

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

   let updateHourAndMin;

   function addition(hoursOrMin) {
      updateHourAndMin =
         hoursOrMin.length < 2
            ? (hoursOrMin = `${0}${hoursOrMin}`)
            : hoursOrMin;

      return updateHourAndMin;
   }

   if (time.endsWith('PM')) {
      hours = parseInt(hours, 10) + 12;
   }

   return `${addition(hours)}:${addition(minutes)}`;
}

console.log(`Converted time: ${convertTo24HrsFormat(time)}`);
Posted by: Guest on January-12-2022

Code answers related to "24 hours time picker with seconds using javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language