codec
codec

Reputation: 8836

How to convert date from one format to another golang

I am converting a date into unix timestamp and fetching the date using split as follows

tm := time.Unix(1470009600, 0).UTC()
dateString := strings.Split(tm.String(), " ")

The output of dateString is 2016-07-15 i.e. YYYY-MM-DD format. How can I convert this into DD-MMM-YY format? eg: 15-Jul-16?

Upvotes: 0

Views: 2984

Answers (1)

Ainar-G
Ainar-G

Reputation: 36259

Use Format method with the appropriate format:

fmt.Println(tm.Format("02-Jan-06")) // Prints "01-Aug-16".

Playground: https://play.golang.org/p/uYDYzPwnbJ.

Upvotes: 2

Related Questions