当前位置:网站首页>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())
}
}
边栏推荐
- Arduino operation stm32
- Guess riddles (6)
- 第十八章 使用工作队列管理器(一)
- [nas1] (2021cvpr) attentivenas: improving neural architecture search via attentive sampling (unfinished)
- PIP installation
- Business modeling of software model | object modeling
- Numpy 小坑:维度 (n, 1) 和 维度 (n, ) 数组相加运算后维度变为 (n, n)
- Infix expression evaluation
- Low code platform | apaas platform construction analysis
- Guess riddles (4)
猜你喜欢
99 multiplication table (C language)
Explore the authentication mechanism of StarUML
实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.
剑指 Offer 05. 替换空格
STM32 summary (HAL Library) - DHT11 temperature sensor (intelligent safety assisted driving system)
Apaas platform of TOP10 abroad
My university
实例007:copy 将一个列表的数据复制到另一个列表中。
Example 002: the bonus paid by the "individual income tax calculation" enterprise is based on the profit commission. When the profit (I) is less than or equal to 100000 yuan, the bonus can be increase
猜谜语啦(4)
随机推荐
How to manage the performance of R & D team?
287. 寻找重复数-快慢指针
Matlab tips (28) fuzzy comprehensive evaluation
Speech recognition learning summary
319. Bulb switch
实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.
Lori remote control commissioning record
[daily training -- Tencent selected 50] 557 Reverse word III in string
Guess riddles (11)
STM32---IIC
Lori remote control LEGO motor
C语言标准函数scanf不安全的原因
Wheel 1:qcustomplot initialization template
整形的分类:short in long longlong
PIP installation
Halcon affine transformations to regions
Tips 1: Web video playback code
Affected tree (tree DP)
Illustration of eight classic pointer written test questions