12 vs 24 Hours

Published by supafly in

Create a function that converts 12-hour time to 24-hour time or vice versa. Return the output as a string.

Examples

ConvertTime("12:00 am") ➞ "0:00"

ConvertTime("6:20 pm") ➞ "18:20"

ConvertTime("21:00") ➞ "9:00 pm"

ConvertTime("5:05") ➞ "5:05 am"

Notes

  • A 12-hour time input will be denoted with an am or pm suffix.
  • A 24-hour input time contains no suffix.
Watch a quick demo on how Edabit works.