You are viewing a single comment's thread. Return to all comments →
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() } }
Seems like cookies are disabled on this browser, please enable them to open this website
Time Conversion
You are viewing a single comment's thread. Return to all comments →
Rust