time.go 758 B

12345678910111213141516171819202122232425262728293031323334
  1. package util
  2. import (
  3. "time"
  4. )
  5. // NowMilli 获得当前时间,毫秒级
  6. func NowMilli() int64 {
  7. return time.Now().Local().UnixNano() / int64(time.Millisecond)
  8. }
  9. // 当天时间的0点
  10. func DayZeroStart(add time.Duration) int64 {
  11. now := time.Now()
  12. startTime := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
  13. startTime = startTime.Add(add)
  14. return startTime.UnixNano() / 1e6
  15. }
  16. // 当天时间的0点
  17. func DayZeroStartTime(add time.Duration) time.Time {
  18. now := time.Now()
  19. startTime := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
  20. startTime = startTime.Add(add)
  21. return startTime
  22. }
  23. func Now13() int64 {
  24. return time.Now().UnixNano() / 1e6
  25. }
  26. func Now10() int64 {
  27. return time.Now().Unix()
  28. }