Browse Source

更新

three
huangjiajun 1 year ago
parent
commit
0575f2749e
1 changed files with 13 additions and 5 deletions
  1. +13
    -5
      app/utils/time.go

+ 13
- 5
app/utils/time.go View File

@@ -168,13 +168,14 @@ func GetTimeRange(s string) map[string]int64 {
// 明天 0点
etime = time.Date(t.Year(), t.Month(), t.Day()+1, 0, 0, 0, 0, t.Location())
case "current_month":
stime = time.Date(t.Year(), t.Month(), 0, 0, 0, 0, 0, t.Location())
etime = time.Date(t.Year(), t.Month()+1, 0, 0, 0, 0, 0, t.Location())
stime = GetFirstDateOfMonth(t)
etime = time.Now()
case "last_month":
stime = time.Date(t.Year(), t.Month()-1, 0, 0, 0, 0, 0, t.Location())
etime = time.Date(t.Year(), t.Month(), 0, 0, 0, 0, 0, t.Location())
etime = GetFirstDateOfMonth(t)
monthTimes := TimeStdParseUnix(etime.Format("2006-01-02 15:04:05")) - 86400
times, _ := UnixToTime(Int64ToStr(monthTimes))
stime = GetFirstDateOfMonth(times)
}

return map[string]int64{
"start": stime.Unix(),
"end": etime.Unix(),
@@ -215,6 +216,13 @@ func GetFirstDateOfMonth(d time.Time) time.Time {
return GetZeroTime(d)
}

//时间戳转时间格式
func UnixToTime(e string) (datatime time.Time, err error) {
data, err := strconv.ParseInt(e, 10, 64)
datatime = time.Unix(data, 0)
return
}

//获取传入的时间所在月份的最后一天,即某月最后一天的0点。如传入time.Now(), 返回当前月份的最后一天0点时间。
func GetLastDateOfMonth(d time.Time) time.Time {
return GetFirstDateOfMonth(d).AddDate(0, 1, -1)


Loading…
Cancel
Save