java.lang.Object | |
↳ | org.joda.time.DateTimeZone |
Known Direct Subclasses |
DateTimeZone represents a time zone.
A time zone is a system of rules to convert time from one geographic location to another. For example, Paris, France is one hour ahead of London, England. Thus when it is 10:00 in London, it is 11:00 in Paris.
All time zone rules are expressed, for historical reasons, relative to Greenwich, London. Local time in Greenwich is referred to as Greenwich Mean Time (GMT). This is similar, but not precisely identical, to Universal Coordinated Time, or UTC. This library only uses the term UTC.
Using this system, America/Los_Angeles is expressed as UTC-08:00, or UTC-07:00 in the summer. The offset -08:00 indicates that America/Los_Angeles time is obtained from UTC by adding -08:00, that is, by subtracting 8 hours.
The offset differs in the summer because of daylight saving time, or DST. The folowing definitions of time are generally used:
Unlike the Java TimeZone class, DateTimeZone is immutable. It also only supports long format time zone ids. Thus EST and ECT are not accepted. However, the factory that accepts a TimeZone will attempt to convert from the old short id to a suitable long id.
DateTimeZone is thread-safe and immutable, and all subclasses must be as well.
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
UTC | The time zone for Universal Coordinated Time |
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructor.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Converts a local instant to a standard UTC instant with the same
local time.
| |||||||||||
Converts a standard UTC instant to a local instant with the same
local time.
| |||||||||||
Compare this datetime zone with another.
| |||||||||||
Gets a time zone instance for the specified time zone id.
| |||||||||||
Gets a time zone instance for the specified offset to UTC in hours.
| |||||||||||
Gets a time zone instance for the specified offset to UTC in hours and minutes.
| |||||||||||
Gets a time zone instance for the specified offset to UTC in milliseconds.
| |||||||||||
Gets a time zone instance for a JDK TimeZone.
| |||||||||||
Gets all the available IDs supported.
| |||||||||||
Gets the default time zone.
| |||||||||||
Gets the ID of this datetime zone.
| |||||||||||
Gets the millisecond instant in another zone keeping the same local time.
| |||||||||||
Gets the long name of this datetime zone suitable for display using
the default locale.
| |||||||||||
Gets the long name of this datetime zone suitable for display using
the specified locale.
| |||||||||||
Returns a non-localized name that is unique to this time zone.
| |||||||||||
Gets the name provider factory.
| |||||||||||
Gets the millisecond offset to add to UTC to get local time.
| |||||||||||
Gets the millisecond offset to add to UTC to get local time.
| |||||||||||
Gets the millisecond offset to subtract from local time to get UTC time.
| |||||||||||
Gets the zone provider factory.
| |||||||||||
Gets the short name of this datetime zone suitable for display using
the default locale.
| |||||||||||
Gets the short name of this datetime zone suitable for display using
the specified locale.
| |||||||||||
Gets the standard millisecond offset to add to UTC to get local time,
when standard time is in effect.
| |||||||||||
Gets a hash code compatable with equals.
| |||||||||||
Returns true if this time zone has no transitions.
| |||||||||||
Checks if the given
LocalDateTime is within a gap. | |||||||||||
Checks whether, at a particular instant, the offset is standard or not.
| |||||||||||
Advances the given instant to where the time zone offset or name changes.
| |||||||||||
Retreats the given instant to where the time zone offset or name changes.
| |||||||||||
Sets the default time zone.
| |||||||||||
Sets the name provider factory.
| |||||||||||
Sets the zone provider factory.
| |||||||||||
Gets the datetime zone as a string, which is simply its ID.
| |||||||||||
Get the datetime zone as a
TimeZone . |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
By default, when DateTimeZones are serialized, only a "stub" object
referring to the id is written out.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Converts a local instant to a standard UTC instant with the same local time. This conversion is used after performing a calculation where the calculation was done using a simple local zone.
instantLocal | the local instant to convert to UTC |
---|---|
strict | whether the conversion should reject non-existent local times |
ArithmeticException | if the result overflows a long |
---|---|
IllegalArgumentException | if the zone has no eqivalent local time |
Converts a standard UTC instant to a local instant with the same local time. This conversion is used before performing a calculation so that the calculation can be done using a simple local zone.
instantUTC | the UTC instant to convert to local |
---|
ArithmeticException | if the result overflows a long |
---|
Compare this datetime zone with another.
object | the object to compare with |
---|
Gets a time zone instance for the specified time zone id.
The time zone id may be one of those returned by getAvailableIDs. Short ids, as accepted by java.util.TimeZone, are not accepted. All IDs must be specified in the long format. The exception is UTC, which is an acceptable id.
Alternatively a locale independent, fixed offset, datetime zone can
be specified. The form [+-]hh:mm
can be used.
id | the ID of the datetime zone, null means default |
---|
IllegalArgumentException | if the ID is not recognised |
---|
Gets a time zone instance for the specified offset to UTC in hours. This method assumes standard length hours.
This factory is a convenient way of constructing zones with a fixed offset.
hoursOffset | the offset in hours from UTC |
---|
IllegalArgumentException | if the offset is too large or too small |
---|
Gets a time zone instance for the specified offset to UTC in hours and minutes. This method assumes 60 minutes in an hour, and standard length minutes.
This factory is a convenient way of constructing zones with a fixed offset. The minutes value is always positive and in the range 0 to 59. If constructed with the values (-2, 30), the resulting zone is '-02:30'.
hoursOffset | the offset in hours from UTC |
---|---|
minutesOffset | the offset in minutes from UTC, must be between 0 and 59 inclusive |
IllegalArgumentException | if the offset or minute is too large or too small |
---|
Gets a time zone instance for the specified offset to UTC in milliseconds.
millisOffset | the offset in millis from UTC |
---|
Gets a time zone instance for a JDK TimeZone.
DateTimeZone only accepts a subset of the IDs from TimeZone. The excluded IDs are the short three letter form (except UTC). This method will attempt to convert between time zones created using the short IDs and the full version.
This method is not designed to parse time zones with rules created by
applications using SimpleTimeZone
directly.
zone | the zone to convert, null means default |
---|
IllegalArgumentException | if the zone is not recognised |
---|
Gets all the available IDs supported.
Gets the default time zone.
The default time zone is derived from the system property user.timezone
.
If that is null
or is not a valid identifier, then the value of the
JDK TimeZone
default is converted. If that fails, UTC
is used.
Gets the ID of this datetime zone.
Gets the millisecond instant in another zone keeping the same local time.
The conversion is performed by converting the specified UTC millis to local millis in this zone, then converting back to UTC millis in the new zone.
newZone | the new zone, null means default |
---|---|
oldInstant | the UTC millisecond instant to convert |
Gets the long name of this datetime zone suitable for display using the default locale.
If the name is not available for the locale, then this method returns a
string in the format [+-]hh:mm
.
instant | milliseconds from 1970-01-01T00:00:00Z to get the name for |
---|
Gets the long name of this datetime zone suitable for display using the specified locale.
If the name is not available for the locale, then this method returns a
string in the format [+-]hh:mm
.
instant | milliseconds from 1970-01-01T00:00:00Z to get the name for |
---|---|
locale | the locale to get the name for |
Returns a non-localized name that is unique to this time zone. It can be combined with id to form a unique key for fetching localized names.
instant | milliseconds from 1970-01-01T00:00:00Z to get the name for |
---|
Gets the name provider factory.
The name provider is a pluggable instance factory that supplies the names of each DateTimeZone.
Gets the millisecond offset to add to UTC to get local time.
instant | instant to get the offset for, null means now |
---|
Gets the millisecond offset to add to UTC to get local time.
instant | milliseconds from 1970-01-01T00:00:00Z to get the offset for |
---|
Gets the millisecond offset to subtract from local time to get UTC time. This offset can be used to undo adding the offset obtained by getOffset.
millisLocal == millisUTC + getOffset(millisUTC) millisUTC == millisLocal - getOffsetFromLocal(millisLocal)NOTE: After calculating millisLocal, some error may be introduced. At offset transitions (due to DST or other historical changes), ranges of local times may map to different UTC times.
This method will return an offset suitable for calculating an instant
after any DST gap. For example, consider a zone with a cutover
from 01:00 to 01:59:
Input: 00:00 Output: 00:00
Input: 00:30 Output: 00:30
Input: 01:00 Output: 02:00
Input: 01:30 Output: 02:30
Input: 02:00 Output: 02:00
Input: 02:30 Output: 02:30
NOTE: The behaviour of this method changed in v1.5, with the emphasis on returning a consistent result later along the time-line (shown above).
instantLocal | the millisecond instant, relative to this time zone, to get the offset for |
---|
Gets the zone provider factory.
The zone provider is a pluggable instance factory that supplies the actual instances of DateTimeZone.
Gets the short name of this datetime zone suitable for display using the default locale.
If the name is not available for the locale, then this method returns a
string in the format [+-]hh:mm
.
instant | milliseconds from 1970-01-01T00:00:00Z to get the name for |
---|
Gets the short name of this datetime zone suitable for display using the specified locale.
If the name is not available for the locale, then this method returns a
string in the format [+-]hh:mm
.
instant | milliseconds from 1970-01-01T00:00:00Z to get the name for |
---|---|
locale | the locale to get the name for |
Gets the standard millisecond offset to add to UTC to get local time, when standard time is in effect.
instant | milliseconds from 1970-01-01T00:00:00Z to get the offset for |
---|
Gets a hash code compatable with equals.
Returns true if this time zone has no transitions.
Checks if the given LocalDateTime
is within a gap.
When switching from standard time to Daylight Savings Time there is typically a gap where a clock hour is missing. This method identifies whether the local datetime refers to such a gap.
localDateTime | the time to check, not null |
---|
Checks whether, at a particular instant, the offset is standard or not.
This method can be used to determine whether Summer Time (DST) applies. As a general rule, if the offset at the specified instant is standard, then either Winter time applies, or there is no Summer Time. If the instant is not standard, then Summer Time applies.
The implementation of the method is simply whether getOffset(long)
equals getStandardOffset(long)
at the specified instant.
instant | milliseconds from 1970-01-01T00:00:00Z to get the offset for |
---|
Advances the given instant to where the time zone offset or name changes. If the instant returned is exactly the same as passed in, then no changes occur after the given instant.
instant | milliseconds from 1970-01-01T00:00:00Z |
---|
Retreats the given instant to where the time zone offset or name changes. If the instant returned is exactly the same as passed in, then no changes occur before the given instant.
instant | milliseconds from 1970-01-01T00:00:00Z |
---|
Sets the default time zone.
zone | the default datetime zone object, must not be null |
---|
IllegalArgumentException | if the zone is null |
---|---|
SecurityException | if the application has insufficient security rights |
Sets the name provider factory.
The name provider is a pluggable instance factory that supplies the names of each DateTimeZone.
nameProvider | provider to use, or null for default |
---|
SecurityException | if you do not have the permission DateTimeZone.setNameProvider |
---|---|
IllegalArgumentException | if the provider is invalid |
Sets the zone provider factory.
The zone provider is a pluggable instance factory that supplies the actual instances of DateTimeZone.
provider | provider to use, or null for default |
---|
SecurityException | if you do not have the permission DateTimeZone.setProvider |
---|---|
IllegalArgumentException | if the provider is invalid |
Gets the datetime zone as a string, which is simply its ID.
Get the datetime zone as a TimeZone
.
By default, when DateTimeZones are serialized, only a "stub" object referring to the id is written out. When the stub is read in, it replaces itself with a DateTimeZone object.
ObjectStreamException |
---|