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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/**
* 获取上周周第一天具体年月日
**/
func GetLastWeekFirstDate() (weekMonday string) {
thisWeekMonday := GetFirstDateOfWeek()
TimeMonday, _ := time.Parse("2006-01-02", thisWeekMonday)
lastWeekMonday := TimeMonday.AddDate(0, 0, -7)
weekMonday = lastWeekMonday.Format("2006-01-02")
return
}
/**
* 获取本周的周一具体年月日
**/
func GetFirstDateOfWeek() (weekMonday string) {
now := time.Now()
offset := int(time.Monday - now.Weekday())
if offset > 0 {
offset = -6
}
weekStartDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
weekMonday = weekStartDate.Format("2006-01-02")
return
}
/**
* 获取上周最后一天具体年月日
**/
func GetLastWeekLastDate() (weekMonday string) {
now := time.Now()
offset := int(time.Monday - now.Weekday())
if offset > 0 {
offset = -6
}
weekStartDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
weekMonday = weekStartDate.AddDate(0, 0, -1).Format("2006-01-02")
return
}
/**
* 获取上周一星期所有天数的具体年月日
**/
func GetBetweenDates(sdate, edate string) []string {
d := []string{}
timeFormatTpl := "2006-01-02 15:04:05"
if len(timeFormatTpl) != len(sdate) {
timeFormatTpl = timeFormatTpl[0:len(sdate)]
}
date, err := time.Parse(timeFormatTpl, sdate)
if err != nil {
return d
}
date2, err := time.Parse(timeFormatTpl, edate)
if err != nil {
return d
}
if date2.Before(date) {
return d
}
// 输出日期格式固定
timeFormatTpl = "2006-01-02"
date2Str := date2.Format(timeFormatTpl)
d = append(d, date.Format(timeFormatTpl))
for {
date = date.AddDate(0, 0, 1)
dateStr := date.Format(timeFormatTpl)
d = append(d, dateStr)
if dateStr == date2Str {
break
}
}
return d
}
|