time.go 381 B

123456789101112131415161718192021222324252627
  1. package common
  2. import (
  3. "strconv"
  4. "time"
  5. )
  6. func TimeFormat1(t time.Time) string {
  7. s := ""
  8. year, month, day := t.Date()
  9. yearStr := strconv.Itoa(year)
  10. monthStr := strconv.Itoa(int(month))
  11. if month < 10 {
  12. monthStr = "0" + monthStr
  13. }
  14. dayStr := strconv.Itoa(day)
  15. if day < 10 {
  16. dayStr = "0" + dayStr
  17. }
  18. s = yearStr + "-" + monthStr + "-" + dayStr + " "
  19. return s
  20. }