func GetHourTime(timeType, start, end string) (startTime, endTime int64) {
switch timeType {
case "1": // 今天
dateNow := time.Now()
startTime = time.Date(dateNow.Year(), dateNow.Month(), dateNow.Day(), 0, 0, 0, 0, dateNow.Location()).Unix()
endTime = time.Date(dateNow.Year(), dateNow.Month(), dateNow.Day(), 23, 59, 59, 0, dateNow.Location()).Unix()
case "2": // 昨天
dateNow := time.Now().AddDate(0, 0, -1)
startTime = time.Date(dateNow.Year(), dateNow.Month(), dateNow.Day(), 0, 0, 0, 0, dateNow.Location()).Unix()
endTime = time.Date(dateNow.Year(), dateNow.Month(), dateNow.Day(), 23, 59, 59, 0, dateNow.Location()).Unix()
case "3": // 前天
dateNow := time.Now().AddDate(0, 0, -2)
startTime = time.Date(dateNow.Year(), dateNow.Month(), dateNow.Day(), 0, 0, 0, 0, dateNow.Location()).Unix()
endTime = time.Date(dateNow.Year(), dateNow.Month(), dateNow.Day(), 23, 59, 59, 0, dateNow.Location()).Unix()
case "4": // 指定日期范围
dateNow := time.Now()
startUnix, _ := time.ParseInLocation("2006-01-02 15:04:05", start, dateNow.Location())
endUnix, _ := time.ParseInLocation("2006-01-02 15:04:05", end, dateNow.Location())
startTime = time.Date(startUnix.Year(), startUnix.Month(), startUnix.Day(), 0, 0, 0, 0, startUnix.Location()).Unix()
endTime = time.Date(endUnix.Year(), endUnix.Month(), endUnix.Day(), 23, 59, 59, 0, endUnix.Location()).Unix()
}
return
}
还没有评论,来说两句吧...