Home »
Java programming language
Java TimeZone getDefault() Method with Example
TimeZone Class getDefault() method: Here, we are going to learn about the getDefault() method of TimeZone Class with its syntax and example.
Submitted by Preeti Jain, on March 13, 2020
TimeZone Class getDefault() method
- getDefault() method is available in java.util package.
- getDefault() method is used to return the default time zone for this host.
- getDefault() method is a static method, it is accessible with the class name and if we try to access the method with the class object then we will not get an error.
- getDefault() method does not throw an exception at the time of getting the default time zone.
Syntax:
public static TimeZone getDefault();
Parameter(s):
- It does not accept any parameter.
Return value:
The return type of the method is TimeZone, it gets this default time zone.
Example:
// Java program to demonstrate the example
// of TimeZone getDefault() method of TimeZone
import java.util.*;
public class GetDefaultOfTimeZone {
public static void main(String args[]) {
// Instantiate TimeZone object
// By using getDefault() method is
// to get the default time zone
TimeZone tz = TimeZone.getDefault();
System.out.println("TimeZone.getDefault(): " + tz);
}
}
Output
TimeZone.getDefault(): sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]