This website uses cookies to enhance the user experience

Convert Time Format

Difficulty: 🔥 Hard

Problem Statement

Given a time in 12-hour AM/PM format, convert it to military (24-hour) time.

Example
Input: 07:05:45PM
Output: 19:05:45
Input: 12:00:00AM
Output: 00:00:00
Constraints
  • The input string will always be in the format hh:mm:ssAM or hh:mm:ssPM.

Expected Challenge Output

When the function convertTimeFormat is called with the given example inputs, the expected outputs are:

  • For the input "07:05:45PM", the output is "19:05:45".
  • For the input "12:00:00AM", the output is "00:00:00".

These outputs represent the time in military format.

console.log(convertTimeFormat('07:05:45PM'));  // Output: '19:05:45'
console.log(convertTimeFormat('12:00:00AM'));  // Output: '00:00:00'
function convertTimeFormat(timeStr) {
// YOUR SOLUTION HERE
}

Memory: 0

CPU: 0