Created
May 19, 2023 08:18
-
-
Save Risyandi/816c410e3c053d76fc65feea283639d1 to your computer and use it in GitHub Desktop.
convert AM/PM 12 hour to 24 hour to time using golang
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 ( | |
"bufio" | |
"fmt" | |
"io" | |
"os" | |
"strings" | |
"time" | |
) | |
func timeConversion(s string) string { | |
// layoutRead and layoutResult | |
// is format first read and final read result | |
layoutRead := "03:04:05PM" | |
layoutResult := "15:04:05" | |
t, _ := time.Parse(layout, string(s)) | |
return t.Format(layoutResult) | |
} | |
func checkError(err error) { | |
if err != nil { | |
panic(err) | |
} | |
} | |
func main() { | |
checkError(err) | |
result := timeConversion(s) | |
fmt.Println(result) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment