【发布时间】:2022-01-05 10:39:53
【问题描述】:
我在我的 API 堆栈中同时使用 Node.js 和 Golang。我需要在 MongoDB 中存储 Date 对象,但在 Golang 中,我不确定如何创建在两种语言之间交叉兼容的 Date 对象。
如何在 golang 中创建 new Date() 以存储在 MongoDB 中?
【问题讨论】:
标签: javascript node.js go time
我在我的 API 堆栈中同时使用 Node.js 和 Golang。我需要在 MongoDB 中存储 Date 对象,但在 Golang 中,我不确定如何创建在两种语言之间交叉兼容的 Date 对象。
如何在 golang 中创建 new Date() 以存储在 MongoDB 中?
【问题讨论】:
标签: javascript node.js go time
您是否使用驱动程序连接到 mongo?很可能它会处理 Go 中的 time.Time 类型和 mongo Date 类型之间的转换。
编辑:为了清楚起见,请尝试:
t := time.Now()
并将 t 直接保存到您的 mongo 文档中
【讨论】: