TimeZone.setDefault(TimeZone) in Java

TimeZone.setDefault(TimeZone): This method is available in java.util.TimeZone class of Java.

Syntax:

void java.util.TimeZone.setDefault(TimeZone zone)

This method takes one argument. This method sets the TimeZone that is returned by the getDefaultmethod. zone is cached. If the zone is null, the cached default TimeZone is cleared.

Parameters: One parameter is required for this method.

zone: the new default TimeZone, or null.

Throws:

SecurityException - if the security manager's check Permissiondenies PropertyPermission("user.timezone","write").

Approach

Java

import java.util.SimpleTimeZone;
import java.util.TimeZone;

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

        TimeZone zone = new SimpleTimeZone(1000, "US");
        TimeZone.setDefault(zone);

        System.out.println(zone);
    }
}

Output:

java.util.SimpleTimeZone[id=US,offset=1000,dstSavings=3600000,useDaylight=false,startYear=0,startMode=0,startMonth=0,startDay=0,startDayOfWeek=0,startTime=0,startTimeMode=0,endMode=0,endMonth=0,endDay=0,endDayOfWeek=0,endTime=0,endTimeMode=0]


No comments:

Post a Comment