Java.util.SimpleTimeZone Class



Introduction

The java.util.SimpleTimeZone class is a concrete subclass of TimeZone that represents a time zone for use with a Gregorian calendar.Following are the important points about SimpleTimeZone −

  • The class holds an offset from GMT, called raw offset.

  • This class also holds start and end rules for a daylight saving time schedule.

Class declaration

Following is the declaration for java.util.SimpleTimeZone class −

public class SimpleTimeZone
   extends TimeZone

Field

Following are the fields for java.util.SimpleTimeZone class −

  • static int STANDARD_TIME − This is the constant for a mode of start or end time specified as standard time.

  • static int UTC_TIME − This is the constant for a mode of start or end time specified as UTC.

  • static int WALL_TIME − This is the constant for a mode of start or end time specified as wall clock time.

It also consists of fields inherited from class TimeZone.

Class constructors

Sr.No. Constructor & Description
1

SimpleTimeZone(int rawOffset, String ID)

This constructs a SimpleTimeZone with the given base time zone offset from GMT and time zone ID with no daylight saving time schedule.

2

SimpleTimeZone(int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime)

This constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, and rules for starting and ending the daylight time.

3

SimpleTimeZone(int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime, int dstSavings)

This constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, and rules for starting and ending the daylight time.

4

SimpleTimeZone(int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int startTimeMode, int endMonth, int endDay, int endDayOfWeek, int endTime, int endTimeMode, int dstSavings)

This constructs a SimpleTimeZone with the given base time zone offset from GMT, time zone ID, and rules for starting and ending the daylight time.

Class methods

Sr.No. Method & Description
1 Object clone()

This method returns a clone of this SimpleTimeZone instance.

2 boolean equals(Object obj)

This method compares the equality of two SimpleTimeZone objects.

3 int getDSTSavings()

This method returns the amount of time in milliseconds that the clock is advanced during daylight saving time.

4 int getOffset(int era, int year, int month, int day, int dayOfWeek, int millis)

This method returns the difference in milliseconds between local time and UTC, taking into account both the raw offset and the effect of daylight saving, for the specified date and time.

5 int getOffset(long date)

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

6 int getRawOffset()

This method gets the GMT offset for this time zone.

7 int hashCode()

This method generates the hash code for the SimpleDateFormat object.

8 boolean hasSameRules(TimeZone other)

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

9 boolean inDaylightTime(Date date)

This method queries if the given date is in daylight saving time.

10 void setDSTSavings(int millisSavedDuringDST)

This method sets the amount of time in milliseconds that the clock is advanced during daylight saving time.

11 void setEndRule(int endMonth, int endDay, int endTime)

This method sets the daylight saving time end rule to a fixed date within a month.

12 void setEndRule(int endMonth, int endDay, int endDayOfWeek, int endTime)

This method sets the daylight saving time end rule.

13 void setEndRule(int endMonth, int endDay, int endDayOfWeek, int endTime, boolean after)

This method sets the daylight saving time end rule to a weekday before or after the given date within a month, e.g., the first Monday on or after the 8th.

14 void setRawOffset(int offsetMillis)

This method sets the base time zone offset to GMT.

15 void setStartRule(int startMonth, int startDay, int startTime)

This method Sets the daylight saving time start rule to a fixed date within a month.

16 void setStartRule(int startMonth, int startDay, int startDayOfWeek, int startTime)

This method sets the daylight saving time start rule.

17 void setStartRule(int startMonth, int startDay, int startDayOfWeek, int startTime, boolean after)

This method Sets the daylight saving time start rule to a weekday before or after the given date within a month, e.g., the first Monday on or after the 8th.

18 void setStartYear(int year)

This method sets the daylight saving time starting year.

19 String toString()

This method returns a string representation of this time zone.

20 boolean useDaylightTime()

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

Methods inherited

This class inherits methods from the following classes −

  • java.util.TimeZone
  • java.util.Object
Advertisements