|
Do you need help with your Java programming?
Click here for instant help with your Java code. |
Get the current TimeZone using the Calendar class
This example shows how to get and display the current timezone using the Calendar class. First we create a Calendar instance using the static method getInstance(). Then call the getTimeZone() method to get a TimeZone object. Finally we call the getDisplayName() method which returns the current timezone as a string, which we send to System.out. |
import java.util.Calendar; import java.util.TimeZone; /** * * @author www.javadb.com * * Displays the current timezone */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { Calendar cal = Calendar.getInstance(); TimeZone timeZone = cal.getTimeZone(); System.out.println(timeZone.getDisplayName()); } } |
| Do you know your Java? | |
| Take a Ten-Question-Java-Quiz! | |
Search for code examples on this site
