Skip to content

Instantly share code, notes, and snippets.

@franklinsales
Created August 13, 2017 17:47
Show Gist options
  • Save franklinsales/b336b46eca4ebbd9f4243cb37987a1e5 to your computer and use it in GitHub Desktop.
Save franklinsales/b336b46eca4ebbd9f4243cb37987a1e5 to your computer and use it in GitHub Desktop.
Convert string with a time to a golang time type.
package main
import (
"fmt"
"time"
)
func main() {
timeFormat := "15:04:05"
myTimeString := "23:03:01"
timeParsed, _ := time.Parse(timeFormat, myTimeString)
fmt.Printf("The type of timeParsed is: %T \n", timeParsed.Format(timeFormat))
fmt.Printf("The value of timeParsed is: %v \n", timeParsed.Format(timeFormat))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment