Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Golang time.Parse() get 0001-01-01 00:00:00 +0000 UTC [duplicate]

Tags:

go

This is my code:

t, _ := time.Parse("12/1/2015 12:00:00", "12/8/2015 12:00:00")
fmt.Println(t)

This is the result: 0001-01-01 00:00:00 +0000 UTC

How to get correct the date string?

Thanks!

like image 355
LiaoL Avatar asked Mar 14 '23 23:03

LiaoL


1 Answers

You need to use the reference timestamp 2006-01-02 15:04:05 for the layout parameter (playground):

t, _ := time.Parse("1/2/2006 15:04:05", "12/8/2015 12:00:00")
like image 61
phihag Avatar answered Mar 25 '23 02:03

phihag