-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os/gtime: TimeZone is Error when using NewFromTime function in gdb #3774
Comments
when using query between start time and end time TimeZone of NewFromTime is also error |
@weimx2023 请检查数据库数据是否正确,2024-08-06 00:00:00和2024-08-05 16:00:00 是sql显示问题,勿惊 startTime, _ := time.Parse(time.RFC3339, "2024-08-05T16:00:00Z")
gStartTime := gtime.NewFromTime(startTime)
gStartTimestamp := gtime.NewFromTimeStamp(startTime.UnixMilli())
fmt.Println("from time", gStartTime)
fmt.Println("from time stamp", gStartTimestamp)
g.
DB().
Model("test_time").
Safe().
Insert(g.Map{
"my_time": gStartTime,
"my_timestamp": gStartTimestamp,
})
mysql连接配置 mysql:root:123456@tcp(127.0.0.1:3306)/test?loc=Local&parseTime=true
表结构
CREATE TABLE `test_time` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`my_timestamp` timestamp NULL DEFAULT NULL,
`my_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB |
@weimx2023 Please check whether the database data is correct, 2024-08-06 00:00:00 and 2024-08-05 16:00:00 are SQL display problems, don’t be alarmed startTime, _ := time.Parse(time.RFC3339, "2024-08-05T16:00:00Z")
gStartTime := gtime.NewFromTime(startTime)
gStartTimestamp := gtime.NewFromTimeStamp(startTime.UnixMilli())
fmt.Println("from time", gStartTime)
fmt.Println("from time stamp", gStartTimestamp)
g.
DB().
Model("test_time").
Safe().
Insert(g.Map{
"my_time": gStartTime,
"my_timestamp": gStartTimestamp,
})
mysql connection configuration mysql:root:123456@tcp(127.0.0.1:3306)/test?loc=Local&parseTime=true
table structure
CREATE TABLE `test_time` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`my_timestamp` timestamp NULL DEFAULT NULL,
`my_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB |
Hi there,I tried it and the time in the database is indeed correct, but this displayed log might cause confusion during debugging. If I directly copy and paste the output SQL statement, the execution result might be different. |
@gqcn 目前初步定位到问题在 修改time格式化后的效果如下, @weimx2023 以下效果是否满意 |
@gqcn At present, the problem has been initially located in the The effect after modifying time formatting is as follows. @weimx2023 Are you satisfied with the following effect? |
@weimx2023 @wln32 其实这个也算是老生常态的问题了,程序的时区和数据库时区不一致,只要时区统一了,不是问题。程序在打印时间的时候不会做任何时区转换,那么主要就是时间对象的时间处理了。建议程序:
若有其他问题欢迎继续提issue。 |
@weimx2023 @wln32 In fact, this is a common problem. The time zone of the program is inconsistent with the time zone of the database. As long as the time zones are unified, it is not a problem. The program will not do any time zone conversion when printing the time, so the main thing is the time processing of the time object. Recommended procedure:
|
@wln32 @gqcn Adding time zones to time is indeed a good idea, but I think it can be clearly explained in the notes. This way, users won't have any confusion when using it. |
不太认同,打印sql语句应当原样输出时间,时区也是时间的一部分,而不是忽略掉,标准库的time类型String方法是带有时区信息的 |
I don’t quite agree. When printing SQL statements, the time should be output as it is. The time zone is also part of the time, rather than ignored. The time type String method of the standard library has time zone information. |
Go version
go version go1.22.5 windows/amd64
GoFrame version
v2.7.2
Can this bug be reproduced with the latest release?
Option Yes
What did you do?
using NewFromTimeStamp function is right
What did you see happen?
the TimeZone is error
What did you expect to see?
fix
The text was updated successfully, but these errors were encountered: