Using the Calendar Class to Display Current Time in Different Time Zones in Java

Description

The following code shows how to using the Calendar Class to Display Current Time in Different Time Zones.

Example


/*w w  w.  j a  v a 2 s .c om*/
import java.util.Calendar;
import java.util.TimeZone;

public class Main {

  public static void main(String[] args) {
    Calendar calNewYork = Calendar.getInstance();
    System.out.println( calNewYork.get(Calendar.HOUR_OF_DAY) + ":"
        + calNewYork.get(Calendar.MINUTE));
        
    calNewYork.setTimeZone(TimeZone.getTimeZone("America/New_York"));

    System.out.println("Time in New York: " + calNewYork.get(Calendar.HOUR_OF_DAY) + ":"
        + calNewYork.get(Calendar.MINUTE));

  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Date »




Date Get
Date Set
Date Format
Date Compare
Date Convert
Date Calculation
Date Parse
Timezone