当前位置:网站首页>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())
}
}
边栏推荐
- Bluebridge cup internet of things competition basic graphic tutorial - clock selection
- Five design details of linear regulator
- Guess riddles (9)
- Guess riddles (5)
- 2022.7.4-----leetcode. one thousand and two hundred
- Is the security account given by Yixue school safe? Where can I open an account
- 剑指 Offer 06. 从尾到头打印链表
- Yolov4 target detection backbone
- Task failed task_ 1641530057069_ 0002_ m_ 000000
- 猜谜语啦(4)
猜你喜欢
Mathematical modeling: factor analysis
99 multiplication table (C language)
MATLAB小技巧(28)模糊綜合評價
Meizu Bluetooth remote control temperature and humidity access homeassistant
Pytorch entry record
Example 009: pause output for one second
[three tier architecture]
Business modeling | process of software model
Low code platform | apaas platform construction analysis
Business modeling of software model | overview
随机推荐
实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.
猜谜语啦(3)
UE pixel stream, come to a "diet pill"!
Search data in geo database
Typical low code apaas manufacturer cases
696. Count binary substring
Halcon blob analysis (ball.hdev)
Illustration of eight classic pointer written test questions
Example 009: pause output for one second
Agile project management of project management
Stm32--- systick timer
Guess riddles (11)
PIP installation
Typescript hands-on tutorial, easy to understand
Business modeling of software model | overview
Low code platform | apaas platform construction analysis
Classification of plastic surgery: short in long long long
猜谜语啦(11)
Sword finger offer 06 Print linked list from end to end
Old Wang's esp8266 and old Wu's ws2818 light strip