From 857ef6f28f9b9fb85163919f31f04f9ea29ba4a3 Mon Sep 17 00:00:00 2001 From: liyp Date: Sun, 21 Apr 2024 11:05:23 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=97=B6=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index b535373..9d9f091 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,12 @@ func insertMessage(db *sql.DB, data map[string]interface{}) error { // id := data["message_id"].(float64) post_type := data["post_type"].(string) message_type := data["message_type"].(string) - message_time := (time.Unix(int64(data["time"].(float64)), 0).UTC()).Format("2006-01-02 15:04:05") + // 设置东八区时间 + loc, err := time.LoadLocation("Asia/Shanghai") + if err != nil { + log.Fatal(err) + } + message_time := (time.Unix(int64(data["time"].(float64)), 0).In(loc)).Format("2006-01-02 15:04:05") group_id := data["group_id"].(float64) message_id := data["message_id"].(float64) raw_message := data["raw_message"].(string) From 6419a12cf37e4eb6d865b3655896e6add9e5ac4c Mon Sep 17 00:00:00 2001 From: liyp Date: Sun, 21 Apr 2024 11:12:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 9d9f091..43e85c5 100644 --- a/main.go +++ b/main.go @@ -45,7 +45,7 @@ func insertMessage(db *sql.DB, data map[string]interface{}) error { sender_role := sender["role"].(string) fmt.Println(post_type, message_time, group_id, message_id, raw_message, sender_user_id, sender_nickname, sender_card, sender_role) // Insert data into database - _, err := db.Exec("INSERT INTO messages ( post_type, message_type, time, group_id, message_id, raw_message, sender_user_id, sender_nickname, sender_card, sender_role) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + _, err = db.Exec("INSERT INTO messages ( post_type, message_type, time, group_id, message_id, raw_message, sender_user_id, sender_nickname, sender_card, sender_role) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", post_type, message_type, message_time, group_id, message_id, raw_message, sender_user_id, sender_nickname, sender_card, sender_role) fmt.Println("Data inserted successfully!") if err != nil {