常用类型及数据操作方法
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
660 B

3 years ago
  1. package helper
  2. import (
  3. "strconv"
  4. "time"
  5. )
  6. func FormatDateTime(str string) string {
  7. date, err := strconv.ParseInt(str, 10, 64)
  8. if err != nil {
  9. return ""
  10. }
  11. return time.Unix(date, 0).Format("2006-01-02 15:04:05")
  12. }
  13. func FormatDate(str string) string {
  14. date, err := strconv.ParseInt(str, 10, 64)
  15. if err != nil {
  16. return ""
  17. }
  18. return time.Unix(date, 0).Format("2006-01-02")
  19. }
  20. //获取当天开始时间戳
  21. func GetTodayStartTimeStamp() int64{
  22. var reserveTime time.Time
  23. loc, _ := time.LoadLocation("Asia/Shanghai")
  24. date := time.Now().Format("2006-01-02")
  25. reserveTime,_ = time.ParseInLocation("2006-01-02",date,loc)
  26. return reserveTime.Unix()
  27. }