第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何使用 Golang Sruct 在 MongoDB 中插入時(shí)間戳?

如何使用 Golang Sruct 在 MongoDB 中插入時(shí)間戳?

Go
Qyouu 2022-10-24 15:08:59
我有以下結(jié)構(gòu):type TypeIncidence struct { Number int bson:"number" json:"number" Description string bson:"description" json:"description" Date_time_stamp string bson:"dateTimeStamp" json:"date_time_stamp" }我想在集合中插入一個(gè)文檔:type TypeIncidence struct {    Number      int    `bson:"number" json:"number"`    Description string `bson:"description" json:"description"`    Date_time_stamp **string?**}var incidence TypeIncidenceincidence.Number = 1Description =" Text"Date_time_stamp = **string?**我必須在 Golang 結(jié)構(gòu)中使用什么數(shù)據(jù)類型來存儲(chǔ) date_time_struct 字符串?如果我想以以下格式存儲(chǔ)'YYYY-MM-DD hh:mm:ss',我應(yīng)該在 golang 中使用什么模塊和/或函數(shù)?(在本地機(jī)器或服務(wù)器轉(zhuǎn)換區(qū)域時(shí)間)提前致謝
查看完整描述

1 回答

?
梵蒂岡之花

TA貢獻(xiàn)1900條經(jīng)驗(yàn) 獲得超5個(gè)贊

您可以使用time.Time

CreatedAt time.Time `json:"created_at" bson:"created_at"`

但是,我建議您存儲(chǔ)Epoch Unix 時(shí)間戳(自 1970 年 1 月 1 日以來的秒數(shù)),因?yàn)樗峭ㄓ玫模?/p>

CreatedAt int64 `json:"created_at" bson:"created_at"`

我過去曾嘗試time.Time通過 Golang 存儲(chǔ)在 MongoDB 中,但是當(dāng)我將相同的信息解析為datetimePython 中的對(duì)象時(shí)遇到了麻煩。如果您希望跨語(yǔ)言和技術(shù)兼容,存儲(chǔ) Epoch Unix 時(shí)間戳將是一個(gè)不錯(cuò)的選擇。


查看完整回答
反對(duì) 回復(fù) 2022-10-24
  • 1 回答
  • 0 關(guān)注
  • 209 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)