当前位置:网站首页>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())
}
}
边栏推荐
- 【日常训练--腾讯精选50】557. 反转字符串中的单词 III
- 图解八道经典指针笔试题
- 【三层架构】
- L298N module use
- 实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.
- How apaas is applied in different organizational structures
- [noi simulation] juice tree (tree DP)
- Agile project management of project management
- UE pixel stream, come to a "diet pill"!
- Some pitfalls of win10 network sharing
猜你喜欢
Example 004: for the day of the day, enter a day of a month of a year to judge the day of the year?
剑指 Offer 05. 替换空格
Guess riddles (4)
STM32 lights up the 1.8-inch screen under Arduino IDE
Halcon affine transformations to regions
Matlab tips (28) fuzzy comprehensive evaluation
Hello everyone, welcome to my CSDN blog!
每日一题——替换空格
Example 007: copy data from one list to another list.
猜谜语啦(10)
随机推荐
剑指 Offer 05. 替换空格
Apaas platform of TOP10 abroad
实例007:copy 将一个列表的数据复制到另一个列表中。
Chapter 18 using work queue manager (1)
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
696. 计数二进制子串
Guess riddles (10)
2022.7.4-----leetcode. one thousand and two hundred
Go dependency injection -- Google open source library wire
How to manage the performance of R & D team?
Daily question - input a date and output the day of the year
Dynamic dimensions required for input: input, but no shapes were provided. Automatically overriding
图解八道经典指针笔试题
319. Bulb switch
Example 009: pause output for one second
Basic number theory -- Euler function
猜谜语啦(5)
Bluebridge cup internet of things basic graphic tutorial - GPIO input key control LD5 on and off
Explore the authentication mechanism of StarUML
Arrangement of some library files