通过系统time来获取上月的开始和结束日期

package main

import (
“fmt”
“time”
)

const DATE_FORMAT = “2006-01-02”

func main() {
year, month, _ := time.Now().Date()
thisMonth := time.Date(year, month, 1, 0, 0, 0, 0, time.Local)
start := thisMonth.AddDate(0, -1, 0).Format(DATE_FORMAT)
end := thisMonth.AddDate(0, 0, -1).Format(DATE_FORMAT)
timeRange := fmt.Sprintf(“%s~%s”, start, end)
fmt.Println(timeRange)
}

发表评论