1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
// 根据时间获取时间范围 周的开始和结束时间
func TimestampWeek(t time.Time) (start, end time.Time) {
t = t.In(time.Local)
st := t.AddDate(0, 0, -(int(t.Weekday() - 1)))
start = time.Date(st.Year(), st.Month(), st.Day(), 0, 0, 0, 0, time.Local)
et := t.AddDate(0, 0, 8-int(t.Weekday()))
end = time.Date(et.Year(), et.Month(), et.Day(), 0, 0, 0, 0, time.Local)
return
}
// 根据时间获取时间范围 日的开始和结束时间
func TimestampDay(t time.Time) (start, end time.Time) {
t = t.In(time.Local)
start = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.Local)
t = t.AddDate(0, 0, 1)
end = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.Local)
return
}
// 根据时间获取时间范围 月的开始和结束时间
func TimestampMonth(t time.Time) (start, end time.Time) {
t = t.In(time.Local)
start = time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, time.Local)
t = start.AddDate(0, 1, 0)
end = time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, time.Local)
return
}
// 根据时间获取时间范围 年的开始和结束时间
func TimestampYear(t time.Time) (start, end time.Time) {
t = t.In(time.Local)
start = time.Date(t.Year(), 1, 1, 0, 0, 0, 0, time.Local)
t = start.AddDate(1, 0, 0)
end = time.Date(t.Year(), 1, 1, 0, 0, 0, 0, time.Local)
return
}
|