2 Replies Latest reply: Feb 13, 2013 6:31 AM by Nitin Khare RSS

    Detecting System Time Zone

    Sreram
      This is in continuation with the following thread.

      default timezone is wrong!

      I have java code running on a server. When the user changes the timezone in the System (say in Windows Control Panel), I had to automatically detect it and send it to the users. If i try to get the timezone via calendar.getTimezone() or TimeZone.getDefault(), I get the timezone information while the java code is started. I don't find a reliable way to get the timezone from the system control panel.

      Is there any method to get the System Timezone in Java?
        • 1. Re: Detecting System Time Zone
          sabre150
          One untested possibility that should be worth trying. Use ProcessBuilder to run a small Java program that returns it's timezone in stdout. Run this periodically from a Timer.
          • 2. Re: Detecting System Time Zone
            Nitin Khare
            Check this related issue: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4216582

            May not be the best way but one approach can be to write a C/C++ wrapper to make a system call to the OS to get the timezone information and call it using native method from your Java code. E.g. for Windows you use GetTimeZoneInformation function (http://msdn.microsoft.com/en-us/library/windows/desktop/ms724421%28v=vs.85%29.aspx)