Answers for "hh:mm:ss AM to 24 hour time convert in node js"

1

convert 24 hours to 12 hours javascript

function tConvert (time) {
  // Check correct time format and split into components
  time = time.toString ().match (/^([01]\d|2[0-3])(:)([0-5]\d)(:[0-5]\d)?$/) || [time];

  if (time.length > 1) { // If time format correct
    time = time.slice (1);  // Remove full string match value
    time[5] = +time[0] < 12 ? 'AM' : 'PM'; // Set AM/PM
    time[0] = +time[0] % 12 || 12; // Adjust hours
  }
  return time.join (''); // return adjusted time or original string
}

tConvert ('18:00:00');
Posted by: Guest on October-17-2020
3

how to convert time to am pm in javascript

var suffix = hour >= 12 ? "PM":"AM";
var hours = ((hour + 11) % 12 + 1) + suffix
Posted by: Guest on April-02-2020
0

hh:mm:ss AM to 24 hour time convert in node js

18:43:25
Posted by: Guest on September-09-2021

Code answers related to "hh:mm:ss AM to 24 hour time convert in node js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language