Search code examples
timegodate-conversion

How do i format time in Go Language


I need to format time like this

Mon, 16 Jun 2014 09:19:01 +0200 

following code

a := time.RFC1123Z

give me

Mon, 02 Jan 2006 15:04:05 -0700

which seem correct but need current time and use now() somehow i guess. but havent figured out how.


Solution

  • You need to use Format for this. time.RFC1123Z is just a layout string.

    t := time.Now()
    s := t.Format(time.RFC1123Z) // Format t to a string using the given layout
    fmt.Println(s)