Time Conversion

Sort by

recency

|

358 Discussions

|

  • + 0 comments

    my approach:

    function timeConversion($s) {
        $mili = date('H:i:s', strtotime($s));
        return $mili;
    }
    
  • + 0 comments

    my approach on the JavaScript solution

    function timeConversion(s) {
        // Write your code here
        let time = s.slice(0,8).split(':');
        let format = s.slice(8);
        if(format === 'PM' && time[0] !== '12') {
            time[0] = (parseInt(time[0]) + 12).toString();
        } else if(format === 'AM' && time[0] === '12') {
            time[0] = '00';
        }
        // Pad hours, minutes, and seconds to ensure two digits
        for(let i = 0; i < time.length; i++) {
            time[i] = time[i].padStart(2, '0');
        }
        return time.join(':');
    }
    
  • + 0 comments

    One testcase i.e 4 failing for me any idea what it is

  • + 0 comments
    def timeConversion(s):
        # Write your code here
        date=datetime.datetime.strptime(s,"%I:%M:%S%p")
        
        date_converted=date.strftime("%H:%M:%S")
        
        return(date_converted)
    
  • + 0 comments

    I gone in a totally different way, with Python 3:

    def timeConversion(s): return(datetime.datetime.strptime(s, "%I:%M:%S%p").time().strftime("%H:%M:%S"))