current := time.Now().UTC()
y, m, d := current.Date()
fmt.Println(y, m, d)
Output:
2009 November 10
How can I get short month name? Like:
2009 Nov 10
Use the Format function with Jan
for short month name, ie
current := time.Now().UTC()
fmt.Println(current.Format("2006 Jan 02"))
Use time.Now().UTC().Format("Jan")
or m.String()[:3]
to get short month name:
current := time.Now().UTC()
y, m, d := current.Date()
fmt.Println(y, m.String()[:3], d)
Also you may use fmt.Sprintf("%d %s %02d", t.Year(), t.Month().String()[:3], t.Day())
like this working sample code:
package main
import "fmt"
import "time"
func main() {
fmt.Println(time.Now().UTC().Format("Jan")) // Aug
t := time.Now()
str := fmt.Sprintf("%d %s %02d", t.Year(), t.Month().String()[:3], t.Day())
fmt.Println(str) // 2016 Aug 03
}
output:
Aug
2016 Aug 03