Home » Java programming language

Java Calendar getTimeZone() Method with Example

Calendar Class getTimeZone() method: Here, we are going to learn about the getTimeZone() method of Calendar Class with its syntax and example.
Submitted by Preeti Jain, on February 01, 2020

Calendar Class getTimeZone() method

  • getTimeZone() method is available in java.util package.
  • getTimeZone() method is used to return this Calendar time zone.
  • getTimeZone() method is a non-static method, it is accessible with the class object and if we try to access the method with the class name then we will get an error.
  • getTimeZone() method does not throw an exception at the time of returning the current Calendar time zone.

Syntax:

    public TimeZone getTimeZone();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of the method is TimeZone, it returns TimeZone of this Calendar.

Example:

// Java Program to demonstrate the example of
// TimeZone getTimeZone() method of Calendar

import java.util.*;

public class GetTimeZone {
    public static void main(String args[]) {
        // Instantiating a Calendar object
        Calendar ca = Calendar.getInstance();

        System.out.println("ca.getTime(): " + ca.getTime());

        // By using getTimeZone() method is to
        // return the time zone of this Calendar
        TimeZone time_zone = ca.getTimeZone();

        //Display time zone of this Calendar
        System.out.println("ca.getTimeZone(): " + time_zone.getDisplayName());
    }
}

Output

ca.getTime(): Mon Jan 27 08:15:04 GMT 2020
ca.getTimeZone(): Greenwich Mean Time


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.