Time Conversion

  • + 0 comments
    function timeConversion(s) {
        // Write your code here
      let sustitute = ""; 
      let newtime = "";
      
      // Debugging
     // s = "12:01:00PM"
    
    
       
       
       if (s.includes("AM")){
        
          if (s.substring(0,2) === "12"){
            
                  sustitute = "00"    
             }
           
            }
        
       
       
       if (s.includes("PM")){
              
        // 1 - 11  
            if(s[0]=== "0" || s[0]=== "1" && s[1] !== "2" ){
                 sustitute =  `${Number(s.substring(0,2)) + 12}`   
          
           }
        
           
        } 
     
      
      newtime = sustitute !== "" ? newtime = s.replace(`${s[0]}${s[1]}`, `${sustitute}`) : s ;
      return newtime.replace(`${s[8]}${s[9]}`, "");  
      
        
    }