package main import ( "fmt" "time" ) func main() { t := time.Now() fmt.Println(t.Format("2006-01-02 15:04:05")) }
package main import ( "fmt" "time" ) func main() { str := "2022-12-25 12:30:00" t, err := time.Parse("2006-01-02 15:04:05", str) if err == nil { fmt.Println(t) } else { fmt.Println(err) } }This code will parse a string in the format of "YYYY-MM-DD HH:MM:SS" into a time value using the "time.Parse()" function. If the string is successfully parsed, the resulting time value will be printed. If there is an error during parsing, the error message will be printed instead. In conclusion, the Time String is an important feature in the "time" package library in Go, which allows us to work with time values in string format. It provides a lot of flexibility in terms of formatting and parsing time values, making it one of the most commonly used features in the Go programming language.