Java时区在运行时发生更改 [英] Java timezone change at runtime

查看:438
本文介绍了Java时区在运行时发生更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的java程序需要使用当前的本地时区来记录事件。问题是,用户有能力更改时区,但即使系统时区发生变化,Java程序也会继续运行旧时区。



我怀疑Java VM设置为运行java程序时的时区(javadoc为 Timezone.setDefault()表示将默认值重置为值它原来是VM初次启动时。)



是真的吗? Java无法将默认时区更新为新的系统时区,因此需要重新启动VM?

解决方案

为什么不设置时区到声明的变量?将其初始化为默认时区,然后如果用户更改它,则将其保存到变量中。调用日志中的变量。


My java program needs to log events with the current local timezone. The problem is, the user has the ability to change the timezone, but even if the system timezone is changed, the java program keeps running with the "old" timezone.

I suspect that the Java VM sets as default the timezone when the java program is run (the javadoc for Timezone.setDefault() says "reset the default to the value it had originally when the VM first started.")

Is that true? Java can't update the default timezone to the new system timezone and therefore requires a restart of the VM?

解决方案

Why not set the timezone to a declared variable? Initialize it as the default timezone, then if the user changes it, you save it to the variable. Call the variable in your logs.

这篇关于Java时区在运行时发生更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆