package main import ( "fmt" "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb" "testing" "time" ) func TestIdTime(T *testing.T) { id := "65713fc86977356f555aded5" objectID := mongodb.StringTOBsonId(id) timestamp := objectID.Timestamp() fmt.Println(timestamp.Format("2006-01-02")) fmt.Println("=============") end := time.Date(2023, 12, 5, 0, 0, 0, 0, time.Local) now := time.Now() var recentDays []string for i := 0; i < 15; i++ { day := now.AddDate(0, 0, -i) // 如果日期在 2023-12-05 及之后,则添加到 recentDays if !day.Before(end) { recentDays = append(recentDays, day.Format("2006-01-02")) } } fmt.Println(recentDays) }