time.go 973 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. #*****************************************************************************
  3. # @file time.go
  4. # @author MakerYang(https://www.makeryang.com)
  5. # @statement 免费课程配套开源项目,任何形式收费均为盗版
  6. #*****************************************************************************
  7. */
  8. package Utils
  9. import (
  10. "strconv"
  11. "time"
  12. )
  13. func TimeFormat(unix int) (string, string) {
  14. timeInt := time.Unix(int64(unix), 0)
  15. return timeInt.Format("2006年01月02日"), timeInt.Format("2006-01-02 15:04:05")
  16. }
  17. func DateFormat(times int) string {
  18. createTime := time.Unix(int64(times), 0)
  19. now := time.Now().Unix()
  20. difTime := now - int64(times)
  21. str := ""
  22. if difTime < 60 {
  23. str = "刚刚"
  24. } else if difTime < 3600 {
  25. M := difTime / 60
  26. str = strconv.Itoa(int(M)) + "分钟前"
  27. } else if difTime < 3600*24 {
  28. H := difTime / 3600
  29. str = strconv.Itoa(int(H)) + "小时前"
  30. } else {
  31. str = createTime.Format("2006-01-02 15:04:05")
  32. }
  33. return str
  34. }