作者:也曾悲摧过_192 | 来源:互联网 | 2023-06-30 18:20
golang日期字符串与时间戳转换获取本地locationtoBeCharge:2015-01-0100:00:00待转化为时间戳的字符串注意这里的小时和分钟还要秒必须写因为是
golang日期字符串与时间戳转换
toBeCharge := "2015-01-01 00:00:00"
timeLayout := "2006-01-02 15:04:05"
loc, _ := time.LoadLocation("Local")
theTime, _ := time.ParseInLocation(timeLayout, toBeCharge, loc)
sr := theTime.Unix()
fmt.Println(theTime)
fmt.Println(sr)
dataTimeStr := time.Unix(sr, 0).Format(timeLayout)
fmt.Println(dataTimeStr)
感谢: studygolang.com/articles/10074
更好的 time.format 类
可以自行查看文档