1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/* Get current TimeZone using Java Calendar This example shows how to get current TimeZone using getTimeZone method of Java Calendar class. */ import java.util.Calendar; import java.util.TimeZone; public class GetCurrentTimeZone { public static void main(String[] args) { //get Calendar instance Calendar now = Calendar.getInstance(); //get current TimeZone using getTimeZone method of Calendar class TimeZone timeZone = now.getTimeZone(); //display current TimeZone using getDisplayName() method of TimeZone class System.out.println("Current TimeZone is : " + timeZone.getDisplayName()); } } /* Typical output would be Current TimeZone is : Eastern Standard Time */ |
Why do we need import java.util.TimeZone;
The program can run without that as well.
import java.util.Calendar;
public class CalendarEx {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
System.out.println(cal.getTimeZone().getDisplayName());
}
}