大背景: java改go
数据库时间类型"timestamp", 存储为当地时间(没有带时区, 且没有做时区偏移处理) : 数据如下
实现: java接口不变, impl由go提供。java使用Date,go使用time.Time接收时间类型。
问题:
1. gorm查询出来的时间是带时区的结构:‘2022-06-15 05:15:28.367 +0000’
2. 在go time.Time严谨的结构来看,原先由java程序存储下来的时间字段值就显得"‘不准确"或者说"不正确"。
3. 将时间字段值 ‘2022-06-15 15:08:00.367 +0000’ 传递给java程序端时,java接收到的字段值是 : “2022-06-15 23:08:00”,自动根据当地的时区做了时区偏移,加了8个小时 :
提问 : 有没有办法在go端处理时区的问题?(去掉时区,或者手动给时间类型字段设置当地的时区)
注 : 目前找到一个“能用但不好用”的办法,需要改动sql查询语句, 在sql查询时指定时区:
SELECT create_time AT TIME ZONE 'PRC' create_time, update_time AT TIME ZONE 'PRC' update_time FROM table WHERE id = ?;
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: a631807682
NOTE: To handle time.Time correctly, you need to include parseTime as a parameter. (more parameters) To fully support UTF-8 encoding, you need to change charset=utf8 to charset=utf8mb4. See this article for a detailed explanation
https://gorm.io/docs/connecting_to_the_database.html#MySQL