java.util.TimeZone.setDefault() Method

Advertisements


Description

The setDefault(TimeZone zone) method is used to set the TimeZone that is returned by the getDefault method.

Declaration

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

public static void setDefault(TimeZone zone)

Parameters

  • zone--This is the new default time zone

Return Value

NA

Exception

  • NA

Example

The following example shows the usage of java.util.TimeZone.setDefault()

package com.tutorialspoint;

import java.util.*;

public class TimeZoneDemo {
   public static void main( String args[] ){
       
      // create time zone object 
      TimeZone tzone = TimeZone.getTimeZone("America/Los_Angeles");
      
      // set time zone to default
      tzone.setDefault(tzone);

      // checking default time zone
      System.out.println("Default time zone:" +tzone);
   }    
}

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

Default time zone:sun.util.calendar.ZoneInfo[id="America/Los_Angeles",
offset=-28800000,dstSavings=3600000,useDaylight=true,transitions=185,
lastRule=java.util.SimpleTimeZone[id=America/Los_Angeles,offset=-28800000,
dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,
startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,
endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]]



Advertisements
Advertisements