java.util
public
abstract
class
java.util.TimeZone
TimeZone is an abstract class which represents a local time zone and its
daylight savings time rules. Subclasses support a particular calendar type,
such as the gregorian calendar.
Please note the type returned by factory methods, i.e. getDefault()
and getTimeZone(String)
, is implementation dependent, so that
it may introduce serialization incompatibility issue between different implementations.
Harmony returns instance of SimpleTimeZone so that the
bytes serialized by Harmony can be deserialized on other implementation successfully,
but the reverse compatibility cannot be guaranteed.
Known Direct Subclasses
SimpleTimeZone |
SimpleTimeZone represents a local time zone and its daylight savings time
rules for the gregorian calendar. |
Summary
Constants
|
|
|
Value |
|
int |
LONG |
The LONG display name style. |
1 |
0x00000001 |
int |
SHORT |
The SHORT display name style. |
0 |
0x00000000 |
Public Constructors
Public Methods
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Constants
public
static
final
int
LONG
The LONG display name style.
Constant Value:
1
(0x00000001)
public
static
final
int
SHORT
The SHORT display name style.
Constant Value:
0
(0x00000000)
Public Constructors
public
TimeZone()
Constructs a new instance of this class.
Public Methods
public
Object
clone()
Returns a new TimeZone with the same ID, rawOffset and daylight savings
time rules as this TimeZone.
Returns
- a shallow copy of this TimeZone
public
static
synchronized
String[]
getAvailableIDs()
Gets the available time zone IDs.
Returns
- an array of time zone ID strings
public
static
synchronized
String[]
getAvailableIDs(int offset)
Gets the available time zone IDs which match the specified offset from
GMT.
Parameters
offset
| the offset from GMT in milliseconds |
Returns
- an array of time zone ID strings
public
int
getDSTSavings()
Gets the daylight savings offset in milliseconds for this TimeZone.
This implementation returns 3600000 (1 hour), or 0 if the time zone does
not observe daylight savings.
Subclasses may override to return daylight savings values other than 1
hour.
Returns
- the daylight savings offset in milliseconds if this TimeZone
observes daylight savings, zero otherwise.
public
static
synchronized
TimeZone
getDefault()
Gets the default time zone.
public
final
String
getDisplayName()
Gets the LONG name for this TimeZone for the default Locale in standard
time. If the name is not available, the result is in the format
GMT[+-]hh:mm.
public
final
String
getDisplayName(boolean daylightTime, int style)
Gets the specified style of name (LONG or SHORT) for this TimeZone for
the default Locale in either standard or daylight time as specified. If
the name is not available, the result is in the format GMT[+-]hh:mm.
Parameters
daylightTime
| true for daylight time, false for standard time |
style
| Either LONG or SHORT |
public
final
String
getDisplayName(Locale locale)
Gets the LONG name for this TimeZone for the specified Locale in standard
time. If the name is not available, the result is in the format
GMT[+-]hh:mm.
public
String
getDisplayName(boolean daylightTime, int style, Locale locale)
Gets the specified style of name (LONG or SHORT) for this TimeZone for
the specified Locale in either standard or daylight time as specified. If
the name is not available, the result is in the format GMT[+-]hh:mm.
Parameters
daylightTime
| true for daylight time, false for standard time |
style
| Either LONG or SHORT |
locale
| the Locale |
public
String
getID()
Gets the ID of this TimeZone.
public
abstract
int
getOffset(int era, int year, int month, int day, int dayOfWeek, int time)
Gets the offset from GMT of this TimeZone for the specified date and
time. The offset includes daylight savings time if the specified date and
time are within the daylight savings time period.
Parameters
era
| the GregorianCalendar era, either GregorianCalendar.BC or
GregorianCalendar.AD |
year
| the year |
month
| the Calendar month |
day
| the day of the month |
dayOfWeek
| the Calendar day of the week |
time
| the time of day in milliseconds |
Returns
- the offset from GMT in milliseconds
public
int
getOffset(long time)
Gets the offset from GMT of this TimeZone for the specified date. The
offset includes daylight savings time if the specified date is within the
daylight savings time period.
Parameters
time
| the date in milliseconds since January 1, 1970 00:00:00 GMT |
Returns
- the offset from GMT in milliseconds
public
abstract
int
getRawOffset()
Gets the offset for standard time from GMT for this TimeZone.
Returns
- the offset from GMT in milliseconds
public
static
synchronized
TimeZone
getTimeZone(String name)
Gets the time zone with the specified ID.
Parameters
name
| a time zone string ID |
Returns
- the time zone with the specified ID or null if a time zone with
the specified ID does not exist
public
boolean
hasSameRules(TimeZone zone)
Returns if the specified TimeZone has the same raw offset as this
TimeZone.
Returns
- true when the TimeZones have the same raw offset, false otherwise
public
abstract
boolean
inDaylightTime(Date time)
Returns if the specified Date is in the daylight savings time period for
this TimeZone.
Returns
- true when the Date is in the daylight savings time period, false
otherwise
public
static
synchronized
void
setDefault(TimeZone timezone)
Sets the default time zone. If passed
null
, then
the next time
getDefault() is called, the default time
zone with be determined. This behavior is slightly different than
the canonical description of this method, but it follows the spirit
of it.
Parameters
timezone
| a TimeZone object
|
public
void
setID(String name)
Sets the ID of this TimeZone.
Parameters
name
| a string which is the time zone ID
|
public
abstract
void
setRawOffset(int offset)
Sets the offset for standard time from GMT for this TimeZone.
Parameters
offset
| the offset from GMT in milliseconds
|
public
abstract
boolean
useDaylightTime()
Returns if this TimeZone has a daylight savings time period.
Returns
- true if this time zone has a daylight savings time period, false
otherwise