当前位置:网站首页>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())
}
}
边栏推荐
- [daily training] 1200 Minimum absolute difference
- 319. 灯泡开关
- Business modeling of software model | vision
- Task failed task_ 1641530057069_ 0002_ m_ 000000
- 猜谜语啦(5)
- Mathematical modeling: factor analysis
- Guess riddles (142)
- Arduino+a4988 control stepper motor
- Low code platform | apaas platform construction analysis
- 每日一题——输入一个日期,输出它是该年的第几天
猜你喜欢

Sword finger offer 05 Replace spaces
![[three tier architecture and JDBC summary]](/img/e0/13d48f2e59b445b9e28e38d45f492d.png)
[three tier architecture and JDBC summary]

Guess riddles (5)

Arduino operation stm32

My university

Guess riddles (11)
![[nas1] (2021cvpr) attentivenas: improving neural architecture search via attentive sampling (unfinished)](/img/3b/c94b8466370f4461875c85b4f66860.png)
[nas1] (2021cvpr) attentivenas: improving neural architecture search via attentive sampling (unfinished)
![[three tier architecture]](/img/73/c4c75a453f03830e83cabb0762eb9b.png)
[three tier architecture]

Business modeling of software model | overview

IT冷知识(更新ing~)
随机推荐
Sword finger offer 09 Implementing queues with two stacks
Bluebridge cup internet of things competition basic graphic tutorial - clock selection
Low code platform | apaas platform construction analysis
Run菜单解析
Guess riddles (2)
Example 007: copy data from one list to another list.
Program error record 1:valueerror: invalid literal for int() with base 10: '2.3‘
剑指 Offer 06. 从尾到头打印链表
[牛客网刷题 Day4] JZ32 从上往下打印二叉树
Some pitfalls of win10 network sharing
319. 灯泡开关
How to manage the performance of R & D team?
Infected Tree(树形dp)
Numpy pit: after the addition of dimension (n, 1) and dimension (n,) array, the dimension becomes (n, n)
Chapter 18 using work queue manager (1)
Shift operation of complement
Guess riddles (11)
STM32---IIC
【三层架构及JDBC总结】
Arrangement of some library files