简体   繁体   English

golang 中的 Node.js new Date() 等价物是什么?

[英]What's the Node.js new Date() equivalent in golang?

I use both Node.js and Golang in my API stack.我在我的 API 堆栈中同时使用 Node.js 和 Golang。 I need to store Date objects in MongoDB, but in Golang, I'm not sure how to create a Date object that's cross compatible between the two languages.我需要将Date对象存储在 MongoDB 中,但在 Golang 中,我不确定如何创建在两种语言之间交叉兼容的Date object。

How do I make a new Date() in golang?如何在 golang 中创建一个new Date()

Are you using a driver to connect to mongo?您是否使用驱动程序连接到 mongo? Odds are it'll take care of the translation between a time.Time type in Go and a mongo Date type for you.奇怪的是,它会为您处理 Go 中的 time.Time 类型和 mongo Date 类型之间的转换。

Edit: To be clear, try:编辑:要清楚,请尝试:

t := time.Now()

and save t directly into your mongo document并将 t 直接保存到您的 mongo 文档中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM