func main(){
loc, _ := time.LoadLocation("Local") //获取时区
timeLayout := "2006-01-02 15:04:05" //转化所需模板
time1 := "2015-03-20 08:50:29" //时间1
time2 := "2015-03-22 08:50:29" //时间2
//将日期转为Time格式
tmp1, _ := time.ParseInLocation(timeLayout, time1, loc)
tmp2, _ := time.ParseInLocation(timeLayout, time2, loc)
timestamp1 := tmp1.Unix() //转化为时间戳 类型是int64
timestamp2 := tmp2.Unix() //转化为时间戳 类型是int64
date := (timestamp2- timestamp1) / 86400 //除以一天的秒数
fmt.Println(date) //输出天数
}