Skip to content

Instantly share code, notes, and snippets.

@srph
Created August 10, 2018 22:04
Show Gist options
  • Save srph/03ba4ab45894fe4eeb8606cd0424f815 to your computer and use it in GitHub Desktop.
Save srph/03ba4ab45894fe4eeb8606cd0424f815 to your computer and use it in GitHub Desktop.
Go: Parse 3:00 AM into military time
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