Java TimeZone getDefault() Method



Description

The Java TimeZone getDefault() method is used to get the default TimeZone for this host. The source of the default TimeZone may vary with implementation.

Declaration

Following is the declaration for java.util.TimeZone.getDefault() method.

public static TimeZone getDefault()

Parameters

NA

Return Value

The method call returns a default TimeZone.

Exception

NA

Getting Default Timezone of the Current Host Example

The following example shows the usage of Java TimeZone getDefault() method to get the default TimeZone object for this host. We've created a TimeZone using getDefault() method and then printed it.

package com.tutorialspoint;

import java.util.TimeZone;

public class TimeZoneDemo {
   public static void main( String args[] ) {

      // create default time zone object
      TimeZone timezonedefault = TimeZone.getDefault();      

      // checking default time zone value          
      System.out.println("Default time zone is :\n" + timezonedefault);
   }    
}

Output

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

Default time zone is :
sun.util.calendar.ZoneInfo[id="Asia/Calcutta",offset=19800000,dstSavings=0,useDaylight=false,transitions=7,lastRule=null]
java_util_timezone.htm
Advertisements