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
| package utils
|
| import (
| "github.com/google/uuid"
| "strings"
| "time"
| )
|
| func GetUUID() string {
| s := uuid.New().String()
| return strings.ReplaceAll(s, "-", "")
| }
|
| // GetLastMonthPeriod 返回上个月的月初时间和月末时间
| func GetLastMonthPeriod() (time.Time, time.Time) {
| // 获取当前时间
| now := time.Now()
|
| // 计算上个月的年份和月份
| lastMonth := now.AddDate(0, -1, 0)
| lastYear, lastMonthNum, _ := lastMonth.Date()
|
| // 获取上个月的第一天的日期(即上个月月初)
| firstDayOfLastMonth := time.Date(lastYear, lastMonthNum, 1, 0, 0, 0, 0, now.Location())
|
| // 获取本月第一天的日期(即本月月初)
| firstDayOfThisMonth := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
|
| // 上个月月末时间即为本月月初减去一秒
| lastDayOfLastMonth := firstDayOfThisMonth.Add(-time.Second)
|
| return firstDayOfLastMonth, lastDayOfLastMonth
| }
|
|