Skip to content

Instantly share code, notes, and snippets.

@dbhalling
Created December 12, 2017 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbhalling/82820813c9687655f307b18b13e00c96 to your computer and use it in GitHub Desktop.
Save dbhalling/82820813c9687655f307b18b13e00c96 to your computer and use it in GitHub Desktop.
#Time Conversion Technical Exam 2
#Time Conversion Technical Exam 2
#puts "Please enter the standard time including the seconds in this format XX:XX:XXAM"
#st = gets.chomp.to_s
st = "12:00:45AM"
#st = "01:12:15PM"
#st = "12:00:00AM"
def solution(st)
if st[8] == "A"
mt = st.delete "AM"
else
mt = st.delete "PM"
mta = mt.chars
h1 = mt[1].to_i + 2
h1.to_s
mta = mta.drop(2)
mta = mta.reverse
mta = mta.push(h1).push("1")
mt = mta.reverse.join("")
end
if st == "12:00:00AM"
mt = "00:00:00"
end
return mt
end
puts "The 24 hour time is #{solution(st)}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment