Home » Core Java » util » Calendar » Get current TimeZone using Calendar

About Ilias Tsagklis

Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.

Get current TimeZone using Calendar

In this example we shall show you how to get the current TimeZone using Calendar. The Calendar is an abstract class that provides methods for converting between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR. To get the current TimeZone using Calendar one should perform the following steps:

  • Use getInstance() API method of Calendar, in order to get a Calendar object, using the default time zone and locale.
  • Use getTimeZone() API method of Calendar, that returns the TimeZone object associated with this calendar. The TimeZone represents a time zone offset, and also figures out daylight savings.
  • Use getDisplayName() API method of TimeZone to get a long standard time name of this TimeZone suitable for presentation to the user in the default locale,

as described in the code snippet below.

package com.javacodegeeks.snippets.core;

import java.util.Calendar;
import java.util.TimeZone;

public class GetCurrentTimeZoneUsingCalendar {
	
	public static void main(String[] args) {
		
		Calendar c = Calendar.getInstance();
		 
		//get current TimeZone using
		TimeZone tz = c.getTimeZone();
		 
		System.out.println("Current TimeZone is : " + tz.getDisplayName());
		
	}

}

Output:

Current TimeZone is : Eastern European Time

 
This was an example of how to get the current TimeZone using Calendar in Java.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

I have read and agree to the terms & conditions

 

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments