How to get current TimeZone using Java Calendar?

We can get current timezone by using getTimeZone method of Calendar class

Following example shows how to get current timezone using Java Calendar:


import java.util.Calendar;

import java.util.TimeZone;

public class CurrentTimeZone {

public static void main(String[] args) {

Calendar curCal = Calendar.getInstance(); // Getting calendar instance

TimeZone timeZone = curCal.getTimeZone(); // To get current time zone callling getTimeZOne

// There is getDisplayName method to get time zone
System.out.println("Current TimeZone is : " + timeZone.getDisplayName());

}
}


Output:
Current TimeZone is : Eastern Standard Time
Share on Google Plus

About Pranav

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment