From 5a9f3f1f5e6fa93c7d873c54f55bdb3c78d5a3d5 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Thu, 20 Jan 2022 19:20:56 +0800 Subject: [PATCH] msg test --- .../db/mysql_model/im_mysql_msg_model/chat_log_model.go | 4 ++-- pkg/utils/time_format.go | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go b/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go index 8455e3885..96d03a7c7 100644 --- a/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go +++ b/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go @@ -28,7 +28,7 @@ func InsertMessageToChatLog(msg pbMsg.MsgDataToMQ) error { chatLog.RecvID = msg.MsgData.RecvID } chatLog.Content = string(msg.MsgData.Content) - chatLog.CreateTime = utils.UnixNanoSecondToTime(msg.MsgData.CreateTime) - chatLog.SendTime = utils.UnixNanoSecondToTime(msg.MsgData.SendTime) + chatLog.CreateTime = utils.UnixMillSecondToTime(msg.MsgData.CreateTime) + chatLog.SendTime = utils.UnixMillSecondToTime(msg.MsgData.SendTime) return dbConn.Table("chat_logs").Create(chatLog).Error } diff --git a/pkg/utils/time_format.go b/pkg/utils/time_format.go index 3accd0567..0587db531 100644 --- a/pkg/utils/time_format.go +++ b/pkg/utils/time_format.go @@ -30,6 +30,11 @@ func UnixSecondToTime(second int64) time.Time { func UnixNanoSecondToTime(nanoSecond int64) time.Time { return time.Unix(0, nanoSecond) } +func UnixMillSecondToTime(millSecond int64) time.Time { + sec := millSecond / 1000 + msec := millSecond % 1000 + return time.Unix(sec, msec*int64(time.Millisecond)) +} //Get the current timestamp by Nano func GetCurrentTimestampByNano() int64 {