Parse Time
Examples in
Go
package main
import (
"fmt"
"time"
)
func main() {
p := fmt.Println
t1, e := time.Parse(
time.RFC3339,
"2012-11-01T22:08:41+00:00")
p(t1)
form := "3 04 PM"
t2, e := time.Parse(form, "8 41 PM")
p(t2)
// Parse will return an error on malformed input explaining the parsing problem.
ansic := "Mon Jan _2 15:04:05 2006"
_, e = time.Parse(ansic, "8:41PM")
p(e)
}
Last Run
:
2012-11-01 22:08:41 +0000 UTC
0000-01-01 20:41:00 +0000 UTC
parsing time "8:41PM" as "Mon Jan _2 15:04:05 2006": cannot parse "8:41PM" as "Mon"