u_time.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package util
  2. import (
  3. "strconv"
  4. "strings"
  5. "time"
  6. )
  7. func GetNowTimeCustom() string {
  8. currentTime := time.Now()
  9. formattedTime := currentTime.Format("2006-01-02-15-04-05")
  10. return formattedTime
  11. }
  12. func TimeCustom1GreaterEqualThanTimeCustom2(timeCustom1 string, timeCustom2 string) bool {
  13. timeInt1, _ := strconv.Atoi(strings.Replace(timeCustom1, "-", "", -1))
  14. timeInt2, _ := strconv.Atoi(strings.Replace(timeCustom2, "-", "", -1))
  15. return timeInt1 >= timeInt2
  16. }
  17. func GetBagTime(bagName string) string {
  18. s1 := strings.Split(bagName, "_")[0]
  19. s1Split := strings.Split(s1, "/")
  20. s2 := s1Split[len(s1Split)-1]
  21. return s2
  22. }
  23. func TimeCustomChange(originalTimeStr string, number int) string {
  24. var newTimeStr string
  25. layout := "2006-01-02-15-04-05"
  26. originalTime, err := time.Parse(layout, originalTimeStr)
  27. if err != nil {
  28. return newTimeStr
  29. }
  30. newTime := originalTime.Add(time.Duration(number) * time.Second)
  31. return newTime.Format(layout)
  32. }
  33. func CalculateDifferenceOfTimeCustom(timeCustom1 string, timeCustom2 string) int {
  34. timeInt1, _ := strconv.Atoi(strings.Replace(timeCustom1, "-", "", -1))
  35. timeInt2, _ := strconv.Atoi(strings.Replace(timeCustom2, "-", "", -1))
  36. return timeInt2 - timeInt1 + 1
  37. }
  38. func TimeCustom1GreaterTimeCustom2(timeCustom1 string, timeCustom2 string) bool {
  39. timeInt1, _ := strconv.Atoi(strings.Replace(timeCustom1, "-", "", -1))
  40. timeInt2, _ := strconv.Atoi(strings.Replace(timeCustom2, "-", "", -1))
  41. return timeInt1 > timeInt2
  42. }
  43. func TimeCustom1LessEqualThanTimeCustom2(timeCustom1 string, timeCustom2 string) bool {
  44. timeInt1, _ := strconv.Atoi(strings.Replace(timeCustom1, "-", "", -1))
  45. timeInt2, _ := strconv.Atoi(strings.Replace(timeCustom2, "-", "", -1))
  46. return timeInt1 <= timeInt2
  47. }