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.