test3.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package main
  2. import (
  3. "fmt"
  4. "math/rand"
  5. // "sort"
  6. "time"
  7. // "strings"
  8. )
  9. func main() {
  10. // str := "http://192.168.1.1:8080"
  11. // str2 := "http://192.168.1.1/wecd"
  12. // str3 := "http://192.168.1.1/"
  13. // str4 := "http://192.168.1.1/erreg/tth"
  14. // fmt.Println(strings.Split(str, "/")[2])
  15. // fmt.Println(strings.Split(str2, "/")[2])
  16. // fmt.Println(strings.Split(str3, "/")[2])
  17. // fmt.Println(strings.Split(str4, "/")[2])
  18. // //fmt.Println(strings.Split(str, "/")[3])
  19. // fmt.Println(strings.Split(str2, "/")[3])
  20. // fmt.Println(strings.Split(str3, "/")[3])
  21. // fmt.Println(strings.Split(str4, "/")[3:])
  22. // fmt.Println(strings.Join(strings.Split(str4, "/")[3:], "/"))
  23. // fmt.Println(len(strings.Split(str, "/")))
  24. // fmt.Println(len(strings.Split(str2, "/")))
  25. // fmt.Println(len(strings.Split(str3, "/")))
  26. // fmt.Println(len(strings.Split(str4, "/")))
  27. // tt := " 22 34 "
  28. // fmt.Println(len(tt))
  29. // fmt.Println("dasdasd", len(strings.Split("2324", " ")))
  30. // fmt.Printf("%s%s", strings.TrimSpace(tt), "ooooo")
  31. // fmt.Println(len(strings.TrimSpace(tt)))
  32. // fmt.Println(1160581.8031 - 328704.2531 - 292244.6031)
  33. //
  34. fmt.Println(GetRemainSeconds(), SecondsUntilEndOfDay())
  35. // fmt.Println(SecondsUntilEndOfDay())
  36. }
  37. func GetRemainSeconds() time.Duration {
  38. now := time.Now()
  39. return time.Date(now.Year(), now.Month(), now.Day()+1, 0, 0, 0, 0, now.Location()).Sub(now)
  40. }
  41. func SecondsUntilEndOfDay() time.Duration {
  42. // 获取当前时间
  43. now := time.Now()
  44. // 构造当天的 23:59:59 时间
  45. endOfDay := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 0, now.Location())
  46. // 计算当前时间与 23:59:59 的时间差
  47. duration := endOfDay.Sub(now)
  48. // 返回剩余的秒数
  49. return duration
  50. }
  51. func SelectNumbers(min, max, count, interval int) []int {
  52. // 生成满足间隔条件的所有数字
  53. var candidates []int
  54. for i := min; i <= max; i += interval {
  55. candidates = append(candidates, i)
  56. }
  57. // 如果可选数量不足,调整 count
  58. if len(candidates) < count {
  59. count = len(candidates)
  60. }
  61. rand.Seed(time.Now().UnixNano())
  62. rand.Shuffle(len(candidates), func(i, j int) {
  63. candidates[i], candidates[j] = candidates[j], candidates[i]
  64. })
  65. // 直接取前 count 个数字
  66. return candidates[:count]
  67. }