Created
March 30, 2017 15:03
-
-
Save ranapu/34bbca846bf7eb3291d5f700e7e1988a to your computer and use it in GitHub Desktop.
Time Conversion in Go
This file contains 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 "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