go timestamp convert date string

1.go convert a date string with a given timestamp

str := time.Unix(1553043424,0).Format("2006-01-02 15:04:05")

2.timestamp int64

timeInt:=time.Now().Unix()

3.go store mysql TIMESTAMP format

t:=time.Now().Format("2006-01-02 15:04:05")
fmt.Println(t)
2017-08-27 02:35:13

4.Convert time string to timestamp

	timeTemplate1 := "2006-01-02 15:04:05"
	startTimeObj, _ := time.ParseInLocation(timeTemplate1, “2020-01-02 15:04:05”, time.Local)
	startTimeInt:=startTimeObj.Unix()
	fmt.Println("----startTime=",startTimeInt)  //1578643191

Leave a Reply

Your email address will not be published.

en_USEnglish