Skip to content

Instantly share code, notes, and snippets.

@Risyandi
Created May 19, 2023 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Risyandi/816c410e3c053d76fc65feea283639d1 to your computer and use it in GitHub Desktop.
Save Risyandi/816c410e3c053d76fc65feea283639d1 to your computer and use it in GitHub Desktop.
convert AM/PM 12 hour to 24 hour to time using golang
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