web_test.go 668 B

12345678910111213141516171819202122232425262728293031
  1. package main
  2. import (
  3. "fmt"
  4. "go.mongodb.org/mongo-driver/bson/primitive"
  5. "testing"
  6. "time"
  7. )
  8. func TestIdTime(T *testing.T) {
  9. id := "65713fc86977356f555aded5"
  10. objectID, _ := primitive.ObjectIDFromHex(id)
  11. timestamp := objectID.Timestamp()
  12. fmt.Println(timestamp.Format("2006-01-02"))
  13. fmt.Println("=============")
  14. end := time.Date(2023, 12, 5, 0, 0, 0, 0, time.Local)
  15. now := time.Now()
  16. var recentDays []string
  17. for i := 0; i < 15; i++ {
  18. day := now.AddDate(0, 0, -i)
  19. // 如果日期在 2023-12-05 及之后,则添加到 recentDays
  20. if !day.Before(end) {
  21. recentDays = append(recentDays, day.Format("2006-01-02"))
  22. }
  23. }
  24. fmt.Println(recentDays)
  25. }