您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

3 周前
1234567891011121314151617181920212223242526272829
  1. package zhios_order_relate_utils
  2. import "time"
  3. func Time2String(date time.Time, format string) string {
  4. if format == "" {
  5. format = "2006-01-02 15:04:05"
  6. }
  7. timeS := date.Format(format)
  8. if timeS == "0001-01-01 00:00:00" {
  9. return ""
  10. }
  11. return timeS
  12. }
  13. func String2Time(timeStr string) time.Time {
  14. toTime, err := time.ParseInLocation("2006-01-02 15:04:05", timeStr, time.Local)
  15. if err != nil {
  16. return time.Now()
  17. }
  18. return toTime
  19. }
  20. //GetDiffDays 获取两个时间相差的天数,0表同一天,正数表t1>t2,负数表t1<t2
  21. func GetDiffDays(t1, t2 time.Time) int {
  22. t1 = time.Date(t1.Year(), t1.Month(), t1.Day(), 0, 0, 0, 0, time.Local)
  23. t2 = time.Date(t2.Year(), t2.Month(), t2.Day(), 0, 0, 0, 0, time.Local)
  24. return int(t1.Sub(t2).Hours() / 24)
  25. }