scrm-go

time_helper.go 805B

12345678910111213141516171819202122232425262728
  1. package utils
  2. import (
  3. "time"
  4. )
  5. // day 当天凌晨0点
  6. func ZeroHourTimeOfDay(day time.Time) time.Time {
  7. dayStr := day.Format("2006-01-02")
  8. zeroHourTime, _ := ParseTimeStringToTime("2006-01-02", dayStr)
  9. return *zeroHourTime
  10. }
  11. // day 当月一号凌晨0点
  12. func BeginningOfMonth(day time.Time) time.Time {
  13. dayStr := day.Format("2006-01")
  14. monthTime, _ := ParseTimeStringToTime("2006-01", dayStr)
  15. return *monthTime
  16. }
  17. // 指定年月的月份的月初凌晨0点和月末23点59分59秒
  18. func MonthBeginningToEnd(year int, month int) (time.Time, time.Time) {
  19. beginningOfMonth := time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
  20. beginningOfNextMonth := beginningOfMonth.AddDate(0, 1, 0)
  21. endOfMonth := beginningOfNextMonth.Add(time.Duration(-1))
  22. return beginningOfMonth, endOfMonth
  23. }