0
我存儲一個變量到MySQL數據庫的VARCHAR(255)
這樣的字段類型:爲什麼我不能將已經RFC3339字符串解析回RFC3339字符串?
ts, err := time.Parse(time.RFC3339, nonce[0:20])
偉大的工程,並顯示了這樣的:
然後當我需要從數據庫中得到它我這樣做:
rows, err := db.Query("SELECT nonce, time FROM noncestore WHERE endpoint=?", endpoint)
var sTimeStamp, nonceHolder string
for rows.Next() {
err = rows.Scan(&nonceHolder, &sTimeStamp)
errCheck(err)
Gives error//>> timeStamp, err := time.Parse(time.RFC3339, sTimeStamp)
errCheck(err)
if timeStamp == ts && nonceHolder == s {
return errors.New("Nonce already used")
}
if now.Sub(timeStamp) < *maxNonceAge {
_, err := db.Query("INSERT INTO noncestore SET nonce=?, time=?, endpoint=?", nonceHolder, sTimeStamp, endpoint)
errCheck(err)
}
}
線上面提到的給了我這個錯誤:
2015/08/14 21:56:18 http: panic serving [::1]:49663: Failed: parsing time "2015-08-15 03:56:00" as "2006-01-02T15:04:05Z07:00": cannot parse " 03:56:00" as "T"
爲什麼它能夠將其轉換爲RFC3339
並將其存儲在數據庫中,但是當談到時間得到它,並格式化回RFC3339
使我可以在我的if語句中使用我遇到錯誤?