DthingApi
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
java.util.TimeZone Class Referenceabstract
Inheritance diagram for java.util.TimeZone:
java.io.Serializable java.util.SimpleTimeZone

Public Member Functions

Object clone ()
 
String getID ()
 
int getDSTSavings ()
 
int getOffset (long time)
 
abstract int getOffset (int era, int year, int month, int day, int dayOfWeek, int timeOfDayMillis)
 
abstract int getRawOffset ()
 
boolean hasSameRules (TimeZone timeZone)
 
abstract boolean inDaylightTime (Date time)
 
void setID (String id)
 
abstract void setRawOffset (int offsetMillis)
 
abstract boolean useDaylightTime ()
 

Static Public Member Functions

static synchronized String [] getAvailableIDs ()
 
static synchronized String [] getAvailableIDs (int offsetMillis)
 
static synchronized TimeZone getDefault ()
 
static native String getDefaultId ()
 
static synchronized TimeZone getTimeZone (String id)
 
static synchronized void setDefault (TimeZone timeZone)
 

Static Public Attributes

static final int SHORT = 0
 
static final int LONG = 1
 

Detailed Description

TimeZone

represents a time zone, primarily used for configuring a Calendar or java.text.SimpleDateFormat instance.

Most applications will use getDefault which returns a

TimeZone

based on the time zone where the program is running.

You can also get a specific

TimeZone

by id.

It is highly unlikely you'll ever want to use anything but the factory methods yourself. Let classes like Calendar and java.text.SimpleDateFormat do the date computations for you.

If you do need to do date computations manually, there are two common cases to take into account:

Note the type returned by the factory methods getDefault and getTimeZone is implementation dependent. This may introduce serialization incompatibility issues between different implementations. Android returns instances of SimpleTimeZone so that the bytes serialized by Android can be deserialized successfully on other implementations, but the reverse compatibility cannot be guaranteed.

See also
Calendar
GregorianCalendar
SimpleDateFormat
SimpleTimeZone

Member Function Documentation

◆ clone()

Object java.util.TimeZone.clone ( )
inline

Returns a new time zone with the same ID, raw offset, and daylight savings time rules as this time zone.

◆ getAvailableIDs() [1/2]

static synchronized String [] java.util.TimeZone.getAvailableIDs ( )
inlinestatic

Returns the system's installed time zone IDs. Any of these IDs can be passed to getTimeZone to lookup the corresponding time zone instance. Currently only support

GMT[+|-]hh[[:]mm]

ids.

◆ getAvailableIDs() [2/2]

static synchronized String [] java.util.TimeZone.getAvailableIDs ( int  offsetMillis)
inlinestatic

Returns the IDs of the time zones whose offset from UTC is

offsetMillis

. Any of these IDs can be passed to getTimeZone to lookup the corresponding time zone instance.

Returns
a possibly-empty array.

◆ getDefault()

static synchronized TimeZone java.util.TimeZone.getDefault ( )
inlinestatic

Returns the user's preferred time zone. This may have been overridden for this process with setDefault.

Since the user's time zone changes dynamically, avoid caching this value. Instead, use this method to look it up for each use.

◆ getDefaultId()

static native String java.util.TimeZone.getDefaultId ( )
static
Returns
The GMT format ID of system default
TimeZone
.

◆ getDSTSavings()

int java.util.TimeZone.getDSTSavings ( )
inline

Returns the daylight savings offset in milliseconds for this time zone. The base implementation returns

3600000

(1 hour) for time zones that use daylight savings time and

0

for timezones that do not. Subclasses should override this method for other daylight savings offsets.

Note that this method doesn't tell you whether or not to apply the offset: you need to call

for the specific time you're interested in. If this method returns a non-zero offset, that only tells you that this

TimeZone

sometimes observes daylight savings.

◆ getID()

String java.util.TimeZone.getID ( )
inline

Returns the ID of this

TimeZone

, such as

America/Los_Angeles

,

GMT-08:00

or

UTC

.

◆ getOffset() [1/2]

int java.util.TimeZone.getOffset ( long  time)
inline

Returns the offset in milliseconds from UTC for this time zone at

time

. The offset includes daylight savings time if the specified date is within the daylight savings time period.

Parameters
timethe date in milliseconds since January 1, 1970 00:00:00 UTC

◆ getOffset() [2/2]

abstract int java.util.TimeZone.getOffset ( int  era,
int  year,
int  month,
int  day,
int  dayOfWeek,
int  timeOfDayMillis 
)
abstract

Returns this time zone's offset in milliseconds from UTC at the specified date and time. The offset includes daylight savings time if the date and time is within the daylight savings time period.

This method is intended to be used by Calendar to compute Calendar#DST_OFFSET and Calendar#ZONE_OFFSET. Application code should have no reason to call this method directly. Each parameter is interpreted in the same way as the corresponding

Calendar

field. Refer to Calendar for specific definitions of this method's parameters.

◆ getRawOffset()

abstract int java.util.TimeZone.getRawOffset ( )
abstract

Returns the offset in milliseconds from UTC of this time zone's standard time.

◆ getTimeZone()

static synchronized TimeZone java.util.TimeZone.getTimeZone ( String  id)
inlinestatic

Returns a

TimeZone

suitable for

id

, or

GMT

on failure.

An id can be an Olson name of the form Area/Location, such as

America/Los_Angeles

. The getAvailableIDs method returns the supported names.

This method can also create a custom

TimeZone

using the following syntax:

GMT[+|-]hh[[:]mm]

. For example,

TimeZone.getTimeZone("GMT+14:00")

would return an object with a raw offset of +14 hours from UTC, and which does not use daylight savings. These are rarely useful, because they don't correspond to time zones actually in use.

Other than the special cases "UTC" and "GMT" (which are synonymous in this context, both corresponding to UTC), Android does not support the deprecated three-letter time zone IDs used in Java 1.1.

◆ hasSameRules()

boolean java.util.TimeZone.hasSameRules ( TimeZone  timeZone)
inline

Returns true if

timeZone

has the same rules as this time zone.

The base implementation returns true if both time zones have the same raw offset.

◆ inDaylightTime()

abstract boolean java.util.TimeZone.inDaylightTime ( Date  time)
abstract

Returns true if

time

is in a daylight savings time period for this time zone.

◆ setDefault()

static synchronized void java.util.TimeZone.setDefault ( TimeZone  timeZone)
inlinestatic

Overrides the default time zone for the current process only.

Warning: avoid using this method to use a custom time zone in your process. This value may be cleared or overwritten at any time, which can cause unexpected behavior. Instead, manually supply a custom time zone as needed.

Parameters
timeZonea custom time zone, or
null
to set the default to the user's preferred value.

◆ setID()

void java.util.TimeZone.setID ( String  id)
inline

Sets the ID of this

TimeZone

.

◆ setRawOffset()

abstract void java.util.TimeZone.setRawOffset ( int  offsetMillis)
abstract

Sets the offset in milliseconds from UTC of this time zone's standard time.

◆ useDaylightTime()

abstract boolean java.util.TimeZone.useDaylightTime ( )
abstract

Returns true if this time zone has a future transition to or from daylight savings time.

Warning: this returns false for time zones like

Asia/Kuala_Lumpur

that have previously used DST but do not currently. A hypothetical country that has never observed daylight savings before but plans to start next year would return true.

Warning: this returns true for time zones that use DST, even when it is not active.

Use inDaylightTime to find out whether daylight savings is in effect at a specific time.

Most applications should not use this method.

Member Data Documentation

◆ LONG

final int java.util.TimeZone.LONG = 1
static

The long display name style, such as

Pacific Daylight Time

. Requests for this style may yield GMT offsets like

GMT-08:00

.

◆ SHORT

final int java.util.TimeZone.SHORT = 0
static

The short display name style, such as

PDT

. Requests for this style may yield GMT offsets like

GMT-08:00

.


The documentation for this class was generated from the following file: