Golang从mongo ISODate解析日期时间

Golang从mongo ISODate解析日期时间,go,Go,我试图解析我从收藏中得到的日期时间 询问 createdBefore := c.QueryParam("createdBefore") if createdBefore != "" { // inside database it contains "createdAt" // "createdAt" : ISODate("2020-11-05T10:03:43.452Z")

我试图解析我从收藏中得到的日期时间

询问

createdBefore := c.QueryParam("createdBefore")
if createdBefore != "" {

    // inside database it contains "createdAt"
    // "createdAt" : ISODate("2020-11-05T10:03:43.452Z")
    datetimer, err := time.Parse("2020-11-05T10:03:43.452Z", createdBefore)
    if err != nil {
        fmt.Println(err)
    }
    fmt.Println(datetimer)

}
错误:

parsing time "2021-11-01T08:23:41.502Z" as "2020-11-05T10:03:43.452Z": cannot parse "-11-01T08:23:41.502Z" as "0-"
0001-01-01 00:00:00 +0000 UTC

使用布局字符串“2006-01-02T15:04:5.000Z”。并阅读文档。在发布问题之前,请尝试搜索您的问题,关于围棋中的解析时间有很多问题。此外,mongo驱动程序会向您提供
time.time
值,您无需自己执行此操作。因此,我的结构是否应为time.time类型?要查询日期/时间值,请在结构中使用
time.time
。驱动程序将自动解析时间。(除非文档中的字段不是一个日期,而是一个字符串)。当我尝试您的解决方案时,我得到:解析时间“2012-11-05 10:29:52.465 Z”作为“2006年01-02T15:04:5.00Z”:不能解析“10:12:52.465 Z”作为“T”01001-01-01 00∶00:0000,UTCIN你的问题你有时间<代码>“2021-11-01T08:23:41.502Z”< /代码>中间有T,所以我为你提供了一个中间有T的布局字符串。在你最后的评论中没有T,但中间有一个空间。因此,将布局字符串调整为该值。请阅读文档,这在
time.Parse()的文档中有解释。对于每一个微小的变化,与其依赖别人的答案,不如理解它。