当前位置:网站首页>golang 基础 —— golang 向 mysql 插入的时间数据和本地时间不一致
golang 基础 —— golang 向 mysql 插入的时间数据和本地时间不一致
2022-07-05 08:41:00 【猎人在吃肉】
问题描述
golang 向 mysql 插入的时间字段的数据时,插入前的时间值是正确的,插入后,在数据库中的 时间值 比 插入前的时间值少了8个小时。
分析
默认时区 和 本地时区不一致造成的。
解析方法
数据库URL配置后面增加 parseTime=true&loc=Local
参数就能解决。
func init() {
Db, err = sql.Open("mysql", "root:[email protected](localhost:3306)/testDB?parseTime=true&loc=Local")
if err != nil {
panic(err.Error())
}
}
边栏推荐
- Is the security account given by Yixue school safe? Where can I open an account
- Guess riddles (3)
- Guess riddles (10)
- Matlab tips (28) fuzzy comprehensive evaluation
- Yolov4 target detection backbone
- Cmder of win artifact
- [牛客网刷题 Day4] JZ35 复杂链表的复制
- Halcon shape_ trans
- Search data in geo database
- Guess riddles (8)
猜你喜欢
Business modeling of software model | object modeling
How to manage the performance of R & D team?
Guess riddles (7)
[nas1] (2021cvpr) attentivenas: improving neural architecture search via attentive sampling (unfinished)
猜谜语啦(11)
MATLAB小技巧(28)模糊綜合評價
实例008:九九乘法表
[牛客网刷题 Day4] JZ55 二叉树的深度
实例010:给人看的时间
Example 009: pause output for one second
随机推荐
Halcon blob analysis (ball.hdev)
Mathematical modeling: factor analysis
How to write cover letter?
[牛客网刷题 Day4] JZ35 复杂链表的复制
[daily training] 1200 Minimum absolute difference
每日一题——替换空格
Guess riddles (9)
Business modeling of software model | vision
Example 003: a complete square is an integer. It is a complete square after adding 100, and it is a complete square after adding 168. What is the number?
STM32 lights up the 1.8-inch screen under Arduino IDE
2022.7.4-----leetcode.1200
Arduino operation stm32
【日常训练】1200. 最小绝对差
Cinq détails de conception du régulateur de tension linéaire
实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.
[nas1] (2021cvpr) attentivenas: improving neural architecture search via attentive sampling (unfinished)
Arrangement of some library files
Tips 1: Web video playback code
Bit operation related operations
Explore the authentication mechanism of StarUML