Time Conversion

Sort by

recency

|

5171 Discussions

|

  • + 0 comments

    Python Soln def timeConversion(s): if s[8:] == "AM": if s[0:2] == "12": return "00" + s[2:8] else: return s[:8] if s[8:] == "PM": if s[0:2] == "12": return s[:8] else: return str(int(s[0:2]) + 12) + s[2:8]

  • + 0 comments

    Rust

    fn timeConversion(s: &str) -> String {
        let prefix = &s[8..10];
        let hour_slc = &s[0..2];
        let minutes = &s[3..5];  
        let seconds = &s[6..8]; 
        let hour_num: i32 = hour_slc.parse().unwrap();
        
        match prefix {
            "AM" => {
                if hour_num == 12 {
                   format!("00:{}:{}", minutes, seconds) 
                } else {
                 format!("{:02}:{}:{}", hour_num, minutes, seconds)
                }
            },
            "PM" => {
                if hour_num == 12 {
                   format!("12:{}:{}", minutes, seconds) 
                } else {
                  let convert_hour = hour_num + 12;
                  format!("{:02}:{}:{}", convert_hour, minutes, seconds)
                }
            },
            _ => "00:00:00".to_string()
        }
    }
    
  • + 0 comments

    Can you help me to integrate this time conversion code into my Ninja Arashi game? I am currently working on building an advance version of the game. So users can enjoy every feature of the game to make it realistic.

  • + 0 comments

    python using array slicing:

    def timeConversion(s): newS = "" if "AM" in s and "12" in s: newS = "00" elif "PM" in s and "12" not in str(s[:2]): newS = str(int(s[:2]) + 12) else: return s[:len(s)-2] return newS + s[2:len(s)-2]

  • + 0 comments

    Loving python... from datetime import datetime

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