Created
August 10, 2018 22:04
-
-
Save srph/03ba4ab45894fe4eeb8606cd0424f815 to your computer and use it in GitHub Desktop.
Go: Parse 3:00 AM into military time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"strconv" | |
"strings" | |
) | |
func parseTime(t string) (int, int) { | |
split := strings.Split(t, " ") | |
time := split[0] | |
period := split[1] | |
timeSplit := strings.Split(time, ":") | |
var hour int | |
if strings.ToLower(period) == "am" { | |
hour = 0 | |
} else { | |
hour = 12 | |
} | |
hourInt, _ := strconv.Atoi(timeSplit[0]) | |
hour = hour + hourInt | |
minutes, _ := strconv.Atoi(timeSplit[1]) | |
return hour, minutes | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment