Java.util.TimeZone Class

Java.util.TimeZone Class

Introduction

The java.util.TimeZone class represents a time zone offset, and also figures out daylight savings.Following are the important points about TimeZone:

  • It takes into consideration various time zone.
  • Through the method used under this class a program running in any country, gets a TimeZone object based on that particular country’s time zone.

Class declaration

Following is the declaration for java.util.TimeZone class:

public abstract class TimeZone
   extends Object
   implements Serializable, Cloneable

Field

Following are the fields for java.util.TimeZone class:

  • static int LONG — This is the style specifier for getDisplayName() indicating a long name, such as “Pacific Standard Time.”
  • static int SHORT — This is the style specifier for getDisplayName() indicating a short name, such as “Pacific.Standard Time”.

Class constructors

S.N.Constructor & Description
1TimeZone()

This constructor is the single constructor for invocation by subclass constructors.

Class methods

S.N.Method & Description
1Object clone()

This method creates a copy of this TimeZon

2static String[] getAvailableIDs()

This method gets all the available IDs supported.

3static String[] getAvailableIDs(int rawOffset)

This method gets the available IDs according to the given time zone offset in milliseconds.

4static TimeZone getDefault()

This method gets the default TimeZone for this host.

5String getDisplayName()

This method returns a name of this time zone suitable for presentation to the user in the default locale.

6String getDisplayName(boolean daylight, int style)

This method returns a name of this time zone suitable for presentation to the user in the default locale.

7String getDisplayName(boolean daylight, int style, Locale locale)

This method returns a name of this time zone suitable for presentation to the user in the specified locale.

8String getDisplayName(Locale locale)

This method returns a name of this time zone suitable for presentation to the user in the specified locale.

9int getDSTSavings()

This method returns the amount of time to be added to local standard time to get local wall clock time.

10String getID()

This method gets the ID of this time zone

11abstract int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds)

This method gets the time zone offset, for current date, modified in case of daylight savings.

12int getOffset(long date)

This method returns the offset of this time zone from UTC at the specified date.

13abstract int getRawOffset()

This method returns the amount of time in milliseconds to add to UTC to get standard time in this time zone.

14static TimeZone getTimeZone(String ID)

This method gets the TimeZone for the given ID.

15boolean hasSameRules(TimeZone other)

This method returns true if this zone has the same rule and offset as another zone.

16abstract boolean inDaylightTime(Date date)

This method queries if the given date is in daylight savings time in this time zone.

17static void setDefault(TimeZone zone)

This method sets the TimeZone that is returned by the getDefault method.

18void setID(String ID)

This method sets the time zone ID

19abstract void setRawOffset(int offsetMillis)

This method sets the base time zone offset to GMT.

20abstract boolean useDaylightTime()

This method queries if this time zone uses daylight savings time.

Methods inherited

This class inherits methods from the following classes:

  • java.util.Object

Was this article helpful?

Related Articles

Leave A Comment?

You must be logged in to post a comment.