Time Conversion

Sort by

recency

|

5140 Discussions

|

  • + 0 comments

    Using datetime tools:

    import os
    import datetime
    
    def timeConversion(s):
        time_format = "%H:%M:%S"
        dt_s = datetime.datetime.strptime(s, "%I:%M:%S%p")
        return datetime.datetime.strftime(dt_s, time_format)
    
    if __name__ == '__main__':
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
        s = input()
        result = timeConversion(s)
    
        fptr.write(result + '\n')
        fptr.close()
    
  • + 0 comments

    JavaScript

    function timeConversion(s) {

    let [hours, minutes, seconds] = s.split(':');
    
    if (hours === '12'){
        hours = '00';
    }
    
    if (seconds.indexOf('PM')  != -1 && hours < 12 ){
        hours = parseInt(hours, 10) + 12;
    }
    
    let conversion = ``${hours}:$`{minutes}:${seconds}`
    
    return conversion.slice(0, -2);
    

    }

  • + 0 comments

    I wanna recieve feedback about my solution in Javascript, I've read other submissions and I know that my code is not de best solution but what things I need to know for code a better solution in a interview?

    function timeConversion(s) {
        // Write your code here
        s.trim() //delete blankspaces if there one
        switch (s[s.length-2]){
            case "A":
            {
                if(s[0]==="1"&&s[1]==="2"){
                    let aux=s.replace(`${s[0]}${s[1]}`,"00")
                    aux = aux.slice(0,s.length-2)
                    return aux
                }else{
                    s= s.slice(0,s.length-2)
                    return s
                }
            }
            case "P":
            {
               if(s[0]==="1"&&s[1]==="2"){
                    s= s.slice(0,s.length-2)
                    return s
                }else{
                let aux=s.slice(0,2)
                aux=(parseInt(aux))+12
                s= s.slice(0,s.length-2)
                s= s.replace(`${s[0]}${s[1]}`, aux.toString())
                return s
                }
            }
        }
    }
    
  • + 0 comments

    Play Wordle Unlimited and enjoy endless word puzzles without waiting for the next day. Challenge your brain daily, improve vocabulary, and have nonstop fun with this addictive word game perfect for all ages. No limits, just pure wordplay! Wordle Unlimited

  • + 0 comments
    def timeConversion(s):
        # Write your code here
        if s[:2] == "12" and s[8:] == "AM":
            return("00" + s[2:8])
    
        elif s[:2] == "12" and s[8:] == "PM":
            return(s[:8])
                    
        elif s[8:] == "PM":
            return(str(int(s[:2])+12) + s[2:8])
        else:
            return(s[:8])