Get TimeZone by name(America/New_York)
import java.util.Calendar;
import java.util.TimeZone;
public class Main {
public static void main(String[] args) {
Calendar calNewYork = Calendar.getInstance();
calNewYork.setTimeZone(TimeZone.getTimeZone("America/New_York"));
System.out.println("Time in New York: " + calNewYork.get(Calendar.HOUR_OF_DAY) + ":"
+ calNewYork.get(Calendar.MINUTE));
}
}
Output:
Time in New York: 11:51
import java.util.Calendar;
import java.util.TimeZone;
public class Main {
public static void main(String[] args) {
Calendar calParis = Calendar.getInstance();
calParis.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
System.out.println("Time in Paris: " + calParis.get(Calendar.HOUR_OF_DAY) + ":"
+ calParis.get(Calendar.MINUTE));
}
}
Output:
Time in Paris: 17:51
import java.util.Calendar;
import java.util.TimeZone;
public class Main {
public static void main(String[] args) {
Calendar calTokyo = Calendar.getInstance();
calTokyo.setTimeZone(TimeZone.getTimeZone("Asia/Tokyo"));
System.out.println("Time in Tokyo: " + calTokyo.get(Calendar.HOUR_OF_DAY) + ":"
+ calTokyo.get(Calendar.MINUTE));
}
}
Output:
Time in Tokyo: 1:51