Set TimeZone for Calendar in Java
Description
The following code shows how to set TimeZone for Calendar.
Example
//from w w w .jav a 2 s. c o m
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));
}
}
The code above generates the following result.