Java.util.GregorianCalendar.getTimeZone() Method

Advertisements


Description

The java.util.GregorianCalendar.getTimeZone() method gets the time zone.

Declaration

Following is the declaration for java.util.GregorianCalendar.getTimeZone() method

public TimeZone getTimeZone()

Parameters

  • NA

Return Value

This method returns the time zone object associated with this calendar.

Exception

  • NA

Example

The following example shows the usage of java.util.GregorianCalendar.getTimeZone() method.

package com.tutorialspoint;

import java.util.*;

public class GregorianCalendarDemo {

   public static void main(String[] args) {

      // create a new calendar
      GregorianCalendar cal =
              (GregorianCalendar) GregorianCalendar.getInstance();

      // print the current date and time
      System.out.println("" + cal.getTime());

      // get the time zone and print it
      System.out.println("Time Zone:" + cal.getTimeZone().getDisplayName());

   }
}

Let us compile and run the above program, this will produce the following result:

Fri May 18 12:43:05 EEST 2012
Time Zone:Eastern European Time



Advertisements
Advertisements