utils.go 549 B

12345678910111213141516171819202122232425
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package util
  4. import (
  5. "strings"
  6. "time"
  7. )
  8. func ParseTime(str string) time.Time {
  9. layOut := "2006-01-02 15:04:05"
  10. if strings.Contains(str, ":") == false && strings.Contains(str, "-") == false {
  11. layOut = "20060102150405"
  12. } else if strings.Contains(str, "T") {
  13. layOut = "2006-01-02T15:04:05"
  14. }
  15. loc, _ := time.LoadLocation("Local")
  16. t, err := time.ParseInLocation(layOut, str, loc)
  17. if err != nil {
  18. return time.Now()
  19. }
  20. return t
  21. }