Parse Time in Go

Posted by yhuang
Public (Editable by Users)
Go
Edit
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)
}