2016-12-06 107 views
1

我在我的應用程序中使用golang和postgreSQL版本9.5.5。我使用「github.com/lib/pq」作爲我的數據庫驅動程序來連接數據庫。我的一個領域有時區的時間戳。我想更新到當前時間。所以我用下面的代碼:無法使用golang在postgres中使用時區更新時間戳

Note:I m using beego as my framework and use orm to compute my queries.

_, err := o.Raw("UPDATE leave SET resultdate=? WHERE leaveid=?", time.Now(), leaveResult.LeaveId).Exec() 

當我執行此我發現了以下錯誤:

"pq: invalid input syntax for type timestamp with time zone: \"09:24:29\"" 

得到任何幫助。

+1

DB期望不同的日期/時間格式的概率很高。例如RFC3339。 嘗試保存,而不是time.Now()與 time.Now()。格式(time.RFC3339) – doharlem

+0

感謝mpmlj。其工作。保存我的一天..... –

+0

真棒!轉移到其他人使用的實際答案。 – doharlem

回答

3

DB預計不同日期/時間格式的概率很高。例如RFC3339。嘗試存儲而不是time.Now()with time.Now()。格式(time.RFC3339)