mongo 的 go 驱动程序返回 bson 时间戳,如https://godoc.org/go.mongodb.org/mongo-driver/bson/primitive#Timestamp 有没有办法将其转换为time.Time
小智 6
https://docs.mongodb.com/manual/reference/bson-types/#timestamps
在mongodb官网可以看到,BSON Timestamps包含两个值,'T' for the seconds since Unix epoch
和'I' for an incrementing ordinal for operations within a given second
。
因此,如果你想将 bson 时间戳转换为 time.Time,你可以使用time.Unix(timestamp.T, 0)