智莺生活mysql模型库
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.
 
 
 
 

30 lines
768 B

  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. }