Skip to content

Instantly share code, notes, and snippets.

@ranapu
Created March 30, 2017 15:03
Show Gist options
  • Save ranapu/34bbca846bf7eb3291d5f700e7e1988a to your computer and use it in GitHub Desktop.
Save ranapu/34bbca846bf7eb3291d5f700e7e1988a to your computer and use it in GitHub Desktop.
Time Conversion in Go
package main
import "fmt"
func main() {
var t string
fmt.Scan(&t)
hr := (int(t[0])-48)*10 + (int(t[1]) - 48)
mn := (int(t[3])-48)*10 + (int(t[4]) - 48)
sd := (int(t[6])-48)*10 + (int(t[7]) - 48)
pm := t[8] == 'P' || t[8] == 'p'
if pm {
if hr != 12 {
hr += 12
}
} else {
if hr == 12 {
hr = 0
}
}
fmt.Printf("%02d:%02d:%02d", hr, mn, sd)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment