TimeZone.getTimeZone(String) in Java

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

Syntax:

TimeZone java.util.TimeZone.getTimeZone(String ID)

This method takes one argument. This method gets the TimeZone for the given ID.

Parameters: One parameter is required for this method.

ID: the ID for a TimeZone, either an abbreviation such as "PST", a full name such as "America/Los_Angeles", or a customID such as "GMT-8:00".

Returns: the specified TimeZone, or the GMT zone if the given ID cannot be understood.

Exceptions: NA

Approach

Java

import java.util.TimeZone;

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

        System.out.println(TimeZone.getTimeZone("US"));
    }
}

Output:

sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]


No comments:

Post a Comment