title: Determine the internet time of another country in Java
body: <p>I am developing a Java application that will be used by people from around the world. One feature requires it to display the current time in Melbourne, Australia.</p>
  
  <p>I have found <a href="https://stackoverflow.com/questions/4442192/how-to-use-an-internet-time-server-to-get-the-time">this</a> answer and adapted the code as follows, but it returns my current time (as expected). It uses the <a href="http://commons.apache.org/proper/commons-net/" rel="nofollow noreferrer">Apache Commons Net library</a>:</p>
  
  <pre><code>    try {
          String TIME_SERVER = "time-a.nist.gov";   
          NTPUDPClient timeClient = new NTPUDPClient();
          InetAddress inetAddress = InetAddress.getByName(TIME_SERVER);
          TimeInfo timeInfo = timeClient.getTime(inetAddress);
          long returnTime = timeInfo.getMessage().getTransmitTimeStamp().getTime();
          return new Date(returnTime);
      } catch (Exception e) {
          System.out.println(e.getMessage());
          return null;
      }
  </code></pre>
  
  <p><strong>How can I modify this code to return the time in Melbourne, rather than my time? I am open to other solutions to solve this problem as well.</strong></p>
  
  <p>Thank you!</p>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>Taking Jon's advice, I have used the <a href="http://www.joda.org/joda-time/" rel="nofollow noreferrer">JodaTime library</a> and built the following code to solve the problem. It can be used for other time zones by changing Australia/Melbourne to <a href="http://en.wikipedia.org/wiki/List_of_tz_database_time_zones" rel="nofollow noreferrer">any timezone found here</a>.</p>
  
  <pre><code>    try {
          //Get the time for the current time zone.
          String TIME_SERVER = "time-a.nist.gov";   
          NTPUDPClient timeClient = new NTPUDPClient();
          InetAddress inetAddress = InetAddress.getByName(TIME_SERVER);
          TimeInfo timeInfo = timeClient.getTime(inetAddress);
          long returnTime = timeInfo.getMessage().getTransmitTimeStamp().getTime();
  
          //Format it to the Melbourne TimeZone.
          DateTimeZone tzMelbourne = DateTimeZone.forID("Australia/Melbourne");
          return new DateTime(returnTime).toDateTime(tzMelbourne);
      } catch (Exception e) {
          System.out.println(e.getMessage());
          return null;
      }
  </code></pre>