java.lang.Object | |||
↳ | org.joda.time.base.AbstractPartial | ||
↳ | org.joda.time.base.BasePartial | ||
↳ | org.joda.time.YearMonthDay |
This class is deprecated.
Use LocalDate which has a much better internal implementation and
has been available since 1.3
YearMonthDay is an immutable partial supporting the year, monthOfYear and dayOfMonth fields.
NOTE: This class only supports the three fields listed above. Thus, you
cannot query the dayOfWeek or centuryOfEra fields for example.
The new LocalDate
class removes this restriction.
Calculations on YearMonthDay are performed using a Chronology
.
This chronology is set to be in the UTC time zone for all calculations.
Each individual field can be queried in two ways:
getMonthOfYear()
monthOfYear().get()
monthOfYear().get()
monthOfYear().getAsText()
monthOfYear().getAsShortText()
monthOfYear().getMaximumValue()
monthOfYear().addToCopy()
monthOfYear().setCopy()
YearMonthDay is thread-safe and immutable, provided that the Chronology is as well. All standard Chronology classes supplied are thread-safe and immutable.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
YearMonthDay.Property | This class is deprecated. Use LocalDate which has a much better internal implementation |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | DAY_OF_MONTH | The index of the dayOfMonth field in the field array | |||||||||
int | MONTH_OF_YEAR | The index of the monthOfYear field in the field array | |||||||||
int | YEAR | The index of the year field in the field array |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a YearMonthDay with the current date, using ISOChronology in
the default zone to extract the fields.
| |||||||||||
Constructs a YearMonthDay with the current date, using ISOChronology in
the specified zone to extract the fields.
| |||||||||||
Constructs a YearMonthDay with the current date, using the specified chronology
and zone to extract the fields.
| |||||||||||
Constructs a YearMonthDay extracting the partial fields from the specified
milliseconds using the ISOChronology in the default zone.
| |||||||||||
Constructs a YearMonthDay extracting the partial fields from the specified
milliseconds using the chronology provided.
| |||||||||||
Constructs a YearMonthDay from an Object that represents a time.
| |||||||||||
Constructs a YearMonthDay from an Object that represents a time, using the
specified chronology.
| |||||||||||
Constructs a YearMonthDay with specified time field values
using
ISOChronology in the default zone. | |||||||||||
Constructs a YearMonthDay with specified time field values.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Get the day of month field property which provides access to advanced functionality.
| |||||||||||
Constructs a YearMonthDay from a
java.util.Calendar
using exactly the same field values avoiding any time zone effects. | |||||||||||
Constructs a YearMonthDay from a
java.util.Date
using exactly the same field values avoiding any time zone effects. | |||||||||||
Get the day of month field value.
| |||||||||||
Gets the field type at the specified index.
| |||||||||||
Gets an array of the field type of each of the fields that this partial supports.
| |||||||||||
Get the month of year field value.
| |||||||||||
Get the year field value.
| |||||||||||
Returns a copy of this date with the specified period taken away.
| |||||||||||
Returns a copy of this date minus the specified number of days.
| |||||||||||
Returns a copy of this date minus the specified number of months.
| |||||||||||
Returns a copy of this date minus the specified number of years.
| |||||||||||
Get the month of year field property which provides access to advanced functionality.
| |||||||||||
Returns a copy of this date with the specified period added.
| |||||||||||
Returns a copy of this date plus the specified number of days.
| |||||||||||
Returns a copy of this date plus the specified number of months.
| |||||||||||
Returns a copy of this date plus the specified number of years.
| |||||||||||
Gets the property object for the specified type, which contains
many useful methods.
| |||||||||||
Gets the number of fields in this partial.
| |||||||||||
Converts this object to a DateMidnight.
| |||||||||||
Converts this object to a DateMidnight in the default time zone.
| |||||||||||
Converts this object to a DateTime using a TimeOfDay to fill in the
missing fields and using the default time zone.
| |||||||||||
Converts this object to a DateTime using a TimeOfDay to fill in the
missing fields.
| |||||||||||
Converts this partial to a full datetime using the default time zone
setting the date fields from this instance and the time fields from
the current time.
| |||||||||||
Converts this partial to a full datetime using the specified time zone
setting the date fields from this instance and the time fields from
the current time.
| |||||||||||
Converts this YearMonthDay to a full datetime at midnight using the
specified time zone.
| |||||||||||
Converts this YearMonthDay to a full datetime at midnight using the
default time zone.
| |||||||||||
Converts this object to an Interval representing the whole day
in the default time zone.
| |||||||||||
Converts this object to an Interval representing the whole day.
| |||||||||||
Converts this object to a LocalDate with the same date and chronology.
| |||||||||||
Output the date in the ISO8601 format YYYY-MM-DD.
| |||||||||||
Returns a copy of this date with the specified chronology.
| |||||||||||
Returns a copy of this date with the day of month field updated.
| |||||||||||
Returns a copy of this date with the specified field set to a new value.
| |||||||||||
Returns a copy of this date with the value of the specified field increased.
| |||||||||||
Returns a copy of this date with the month of year field updated.
| |||||||||||
Returns a copy of this date with the specified period added.
| |||||||||||
Returns a copy of this date with the year field updated.
| |||||||||||
Get the year field property which provides access to advanced functionality.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Gets the field for a specific index in the chronology specified.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.joda.time.base.BasePartial
| |||||||||||
From class
org.joda.time.base.AbstractPartial
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.lang.Comparable
| |||||||||||
From interface
org.joda.time.ReadablePartial
|
The index of the dayOfMonth field in the field array
The index of the monthOfYear field in the field array
The index of the year field in the field array
Constructs a YearMonthDay with the current date, using ISOChronology in the default zone to extract the fields.
The constructor uses the default time zone, resulting in the local time being initialised. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).
Constructs a YearMonthDay with the current date, using ISOChronology in the specified zone to extract the fields.
The constructor uses the specified time zone to obtain the current date. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).
zone | the zone to use, null means default zone |
---|
Constructs a YearMonthDay with the current date, using the specified chronology and zone to extract the fields.
The constructor uses the time zone of the chronology specified. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).
chronology | the chronology, null means ISOChronology in the default zone |
---|
Constructs a YearMonthDay extracting the partial fields from the specified milliseconds using the ISOChronology in the default zone.
The constructor uses the default time zone, resulting in the local time being initialised. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).
instant | the milliseconds from 1970-01-01T00:00:00Z |
---|
Constructs a YearMonthDay extracting the partial fields from the specified milliseconds using the chronology provided.
The constructor uses the time zone of the chronology specified. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).
instant | the milliseconds from 1970-01-01T00:00:00Z |
---|---|
chronology | the chronology, null means ISOChronology in the default zone |
Constructs a YearMonthDay from an Object that represents a time.
The recognised object types are defined in
ConverterManager
and
include ReadableInstant, String, Calendar and Date.
The String formats are described by dateOptionalTimeParser()
.
The chronology used will be derived from the object, defaulting to ISO.
NOTE: Prior to v1.3 the string format was described by
dateTimeParser()
. Time ony strings are now rejected.
instant | the datetime object, null means now |
---|
IllegalArgumentException | if the instant is invalid |
---|
Constructs a YearMonthDay from an Object that represents a time, using the specified chronology.
The recognised object types are defined in
ConverterManager
and
include ReadableInstant, String, Calendar and Date.
The String formats are described by dateOptionalTimeParser()
.
The constructor uses the time zone of the chronology specified. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC). The specified chronology overrides that of the object.
NOTE: Prior to v1.3 the string format was described by
dateTimeParser()
. Time only strings are now rejected.
instant | the datetime object, null means now |
---|---|
chronology | the chronology, null means ISO default |
IllegalArgumentException | if the instant is invalid |
---|
Constructs a YearMonthDay with specified time field values
using ISOChronology
in the default zone.
The constructor uses the no time zone initialising the fields as provided. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).
year | the year |
---|---|
monthOfYear | the month of the year |
dayOfMonth | the day of the month |
Constructs a YearMonthDay with specified time field values.
The constructor uses the time zone of the chronology specified. Once the constructor is complete, all further calculations are performed without reference to a timezone (by switching to UTC).
year | the year |
---|---|
monthOfYear | the month of the year |
dayOfMonth | the day of the month |
chronology | the chronology, null means ISOChronology in the default zone |
Get the day of month field property which provides access to advanced functionality.
Constructs a YearMonthDay from a java.util.Calendar
using exactly the same field values avoiding any time zone effects.
Each field is queried from the Calendar and assigned to the YearMonthDay. This is useful if you have been using the Calendar as a local date, ignoing the zone.
This factory method ignores the type of the calendar and always
creates a YearMonthDay with ISO chronology. It is expected that you
will only pass in instances of GregorianCalendar
however
this is not validated.
calendar | the Calendar to extract fields from |
---|
IllegalArgumentException | if the calendar is null |
---|---|
IllegalArgumentException | if the date is invalid for the ISO chronology |
Constructs a YearMonthDay from a java.util.Date
using exactly the same field values avoiding any time zone effects.
Each field is queried from the Date and assigned to the YearMonthDay. This is useful if you have been using the Date as a local date, ignoing the zone.
This factory method always creates a YearMonthDay with ISO chronology.
date | the Date to extract fields from |
---|
IllegalArgumentException | if the calendar is null |
---|---|
IllegalArgumentException | if the date is invalid for the ISO chronology |
Get the day of month field value.
Gets the field type at the specified index.
index | the index to retrieve |
---|
IndexOutOfBoundsException | if the index is invalid |
---|
Gets an array of the field type of each of the fields that this partial supports.
The fields are returned largest to smallest, Year, Month, Day
Get the month of year field value.
Get the year field value.
Returns a copy of this date with the specified period taken away.
If the amount is zero or null, then this
is returned.
This method is typically used to subtract complex period instances.
Subtracting one field is best achieved using methods
like minusYears(int)
.
period | the period to reduce this instant by |
---|
ArithmeticException | if the new datetime exceeds the capacity of a long |
---|
Returns a copy of this date minus the specified number of days.
This datetime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
YearMonthDay subtracted = dt.minusDays(6); YearMonthDay subtracted = dt.minus(Period.days(6)); YearMonthDay subtracted = dt.withFieldAdded(DurationFieldType.days(), -6);
days | the amount of days to subtract, may be negative |
---|
Returns a copy of this date minus the specified number of months.
This datetime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
YearMonthDay subtracted = dt.minusMonths(6); YearMonthDay subtracted = dt.minus(Period.months(6)); YearMonthDay subtracted = dt.withFieldAdded(DurationFieldType.months(), -6);
months | the amount of months to subtract, may be negative |
---|
Returns a copy of this date minus the specified number of years.
This datetime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
YearMonthDay subtracted = dt.minusYears(6); YearMonthDay subtracted = dt.minus(Period.years(6)); YearMonthDay subtracted = dt.withFieldAdded(DurationFieldType.years(), -6);
years | the amount of years to subtract, may be negative |
---|
Get the month of year field property which provides access to advanced functionality.
Returns a copy of this date with the specified period added.
If the amount is zero or null, then this
is returned.
This method is typically used to add complex period instances.
Adding one field is best achieved using methods
like plusYears(int)
.
period | the duration to add to this one, null means zero |
---|
ArithmeticException | if the new datetime exceeds the capacity of a long |
---|
Returns a copy of this date plus the specified number of days.
This date instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
YearMonthDay added = dt.plusDays(6); YearMonthDay added = dt.plus(Period.days(6)); YearMonthDay added = dt.withFieldAdded(DurationFieldType.days(), 6);
days | the amount of days to add, may be negative |
---|
Returns a copy of this date plus the specified number of months.
This date instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
YearMonthDay added = dt.plusMonths(6); YearMonthDay added = dt.plus(Period.months(6)); YearMonthDay added = dt.withFieldAdded(DurationFieldType.months(), 6);
months | the amount of months to add, may be negative |
---|
Returns a copy of this date plus the specified number of years.
This date instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
YearMonthDay added = dt.plusYears(6); YearMonthDay added = dt.plus(Period.years(6)); YearMonthDay added = dt.withFieldAdded(DurationFieldType.years(), 6);
years | the amount of years to add, may be negative |
---|
Gets the property object for the specified type, which contains many useful methods.
type | the field type to get the property for |
---|
IllegalArgumentException | if the field is null or unsupported |
---|
Gets the number of fields in this partial.
Converts this object to a DateMidnight.
zone | the zone to get the DateMidnight in, null means default |
---|
Converts this object to a DateMidnight in the default time zone.
Converts this object to a DateTime using a TimeOfDay to fill in the missing fields and using the default time zone. This instance is immutable and unaffected by this method call.
The resulting chronology is determined by the chronology of this YearMonthDay plus the time zone. The chronology of the time is ignored - only the field values are used.
time | the time of day to use, null means current time |
---|
Converts this object to a DateTime using a TimeOfDay to fill in the missing fields. This instance is immutable and unaffected by this method call.
The resulting chronology is determined by the chronology of this YearMonthDay plus the time zone. The chronology of the time is ignored - only the field values are used.
time | the time of day to use, null means current time |
---|---|
zone | the zone to get the DateTime in, null means default |
Converts this partial to a full datetime using the default time zone setting the date fields from this instance and the time fields from the current time.
Converts this partial to a full datetime using the specified time zone setting the date fields from this instance and the time fields from the current time.
This method uses the chronology from this instance plus the time zone specified.
zone | the zone to use, null means default |
---|
Converts this YearMonthDay to a full datetime at midnight using the specified time zone.
This method uses the chronology from this instance plus the time zone specified.
zone | the zone to use, null means default |
---|
Converts this YearMonthDay to a full datetime at midnight using the default time zone.
Converts this object to an Interval representing the whole day in the default time zone.
Converts this object to an Interval representing the whole day.
zone | the zone to get the Interval in, null means default |
---|
Converts this object to a LocalDate with the same date and chronology.
Output the date in the ISO8601 format YYYY-MM-DD.
Returns a copy of this date with the specified chronology. This instance is immutable and unaffected by this method call.
This method retains the values of the fields, thus the result will typically refer to a different instant.
The time zone of the specified chronology is ignored, as YearMonthDay operates without a time zone.
newChronology | the new chronology, null means ISO |
---|
IllegalArgumentException | if the values are invalid for the new chronology |
---|
Returns a copy of this date with the day of month field updated.
YearMonthDay is immutable, so there are no set methods. Instead, this method returns a new instance with the value of day of month changed.
dayOfMonth | the day of month to set |
---|
IllegalArgumentException | if the value is invalid |
---|
Returns a copy of this date with the specified field set to a new value.
For example, if the field type is dayOfMonth
then the day
would be changed in the returned instance.
These three lines are equivalent:
YearMonthDay updated = ymd.withField(DateTimeFieldType.dayOfMonth(), 6); YearMonthDay updated = ymd.dayOfMonth().setCopy(6); YearMonthDay updated = ymd.property(DateTimeFieldType.dayOfMonth()).setCopy(6);
fieldType | the field type to set, not null |
---|---|
value | the value to set |
IllegalArgumentException | if the value is null or invalid |
---|
Returns a copy of this date with the value of the specified field increased.
If the addition is zero, then this
is returned.
These three lines are equivalent:
YearMonthDay added = ymd.withFieldAdded(DurationFieldType.days(), 6); YearMonthDay added = ymd.plusDays(6); YearMonthDay added = ymd.dayOfMonth().addToCopy(6);
fieldType | the field type to add to, not null |
---|---|
amount | the amount to add |
IllegalArgumentException | if the value is null or invalid |
---|---|
ArithmeticException | if the new datetime exceeds the capacity |
Returns a copy of this date with the month of year field updated.
YearMonthDay is immutable, so there are no set methods. Instead, this method returns a new instance with the value of month of year changed.
monthOfYear | the month of year to set |
---|
IllegalArgumentException | if the value is invalid |
---|
Returns a copy of this date with the specified period added.
If the addition is zero, then this
is returned.
Fields in the period that aren't present in the partial are ignored.
This method is typically used to add multiple copies of complex
period instances. Adding one field is best achieved using methods
like withFieldAdded(DurationFieldType, int)
or plusYears(int)
.
period | the period to add to this one, null means zero |
---|---|
scalar | the amount of times to add, such as -1 to subtract once |
ArithmeticException | if the new datetime exceeds the capacity |
---|
Returns a copy of this date with the year field updated.
YearMonthDay is immutable, so there are no set methods. Instead, this method returns a new instance with the value of year changed.
year | the year to set |
---|
IllegalArgumentException | if the value is invalid |
---|
Get the year field property which provides access to advanced functionality.
Gets the field for a specific index in the chronology specified.
This method must not use any instance variables.
index | the index to retrieve |
---|---|
chrono | the chronology to use |