Skip to content
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

时区错误问题 #138

Open
fatcarter opened this issue Jan 12, 2024 · 6 comments
Open

时区错误问题 #138

fatcarter opened this issue Jan 12, 2024 · 6 comments

Comments

@fatcarter
Copy link

TSDBJNIConnector类

private static void handleTimeZone(String posixTimeZoneStr) {
        if (posixTimeZoneStr.startsWith("UTC") || posixTimeZoneStr.startsWith("GMT")) {
            if (posixTimeZoneStr.length() == 3) {
                TimeZone.setDefault(TimeZone.getTimeZone(ZoneId.of("GMT")));
                return;
            }

            String regex = "^(UTC|GMT)([+-])(\\d+)$";
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(posixTimeZoneStr);
            if (matcher.matches()) {
                String op = matcher.group(2);
                String hourStr = matcher.group(3);
                // 这里+ 为什么要变成-
                if (op.equals("+")) {
                    op = "-";
                } else {
                    op = "+";
                }

                int hour = Integer.parseInt(hourStr);
                if (hour > 18) {
                    return;
                }

                String timezone = String.format("GMT%s%02d:00", op, hour);
                // 这里为什么要设置默认时区,导致我jvm设置user.timezone都给覆盖了
                TimeZone.setDefault(TimeZone.getTimeZone(ZoneId.of(timezone)));
                return;
            }
        }

        if (posixTimeZoneStr.contains("/")) {
            TimeZone.setDefault(TimeZone.getTimeZone(ZoneId.of(posixTimeZoneStr)));
        }

    }
@fatcarter
Copy link
Author

我现在整个服务获取到的时区都是 GMT-8时区,真是离了大普

@fatcarter
Copy link
Author

提交来自这里: a1de417

处理时区,请不要覆盖默认时区

@fatcarter
Copy link
Author

3.2.7

@Chuangyu
Copy link

这个应该是 #135 的原因

@sheyanjie-qq
Copy link
Contributor

时区设置本来就是 jvm 级别的,否则没办法处理返回结果的时间。
如果你之前通过别的数据库参数正确设置了 JVM 时区,可以不在 taos-jdbc-driver 中设置。
由于历史原因, taos-jdbc-driver 参数中的时区是 posix 规范,所以 posix 规范的 GMT-8 会改成 jvm 规范的 GMT+8, 官方文档中也说明的这一点

@Chuangyu
Copy link

Chuangyu commented Dec 5, 2024

设置默认时区这个愚蠢的错误到现在还没有纠正,我也是呵呵了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants