public static final class DateTime.Property extends AbstractReadableInstantFieldProperty
The simplest use of this class is as an alternative get method, here used to get the year '1972' (as an int) and the month 'December' (as a String).
DateTime dt = new DateTime(1972, 12, 3, 0, 0, 0, 0); int year = dt.year().get(); String monthStr = dt.month().getAsText();
Methods are also provided that allow date modification. These return new instances of DateTime - they do not modify the original. The example below yields two independent immutable date objects 20 years apart.
DateTime dt = new DateTime(1972, 12, 3, 0, 0, 0, 0); DateTime dt20 = dt.year().addToCopy(20);Serious modification of dates (ie. more than just changing one or two fields) should use the
MutableDateTime
class.
DateTime.Propery itself is thread-safe and immutable, as well as the DateTime being operated on.
Modifier and Type | Method and Description |
---|---|
DateTime |
addToCopy(int value)
Adds to this field in a copy of this DateTime.
|
DateTime |
addToCopy(long value)
Adds to this field in a copy of this DateTime.
|
DateTime |
addWrapFieldToCopy(int value)
Adds to this field, possibly wrapped, in a copy of this DateTime.
|
protected Chronology |
getChronology()
Gets the chronology of the datetime that this property is linked to.
|
DateTime |
getDateTime()
Gets the datetime being used.
|
DateTimeField |
getField()
Gets the field being used.
|
protected long |
getMillis()
Gets the milliseconds of the datetime that this property is linked to.
|
DateTime |
roundCeilingCopy()
Rounds to the highest whole unit of this field on a copy of this DateTime.
|
DateTime |
roundFloorCopy()
Rounds to the lowest whole unit of this field on a copy of this DateTime.
|
DateTime |
roundHalfCeilingCopy()
Rounds to the nearest whole unit of this field on a copy of this DateTime,
favoring the ceiling if halfway.
|
DateTime |
roundHalfEvenCopy()
Rounds to the nearest whole unit of this field on a copy of this
DateTime.
|
DateTime |
roundHalfFloorCopy()
Rounds to the nearest whole unit of this field on a copy of this DateTime,
favoring the floor if halfway.
|
DateTime |
setCopy(int value)
Sets this field in a copy of the DateTime.
|
DateTime |
setCopy(String text)
Sets this field in a copy of the DateTime to a parsed text value.
|
DateTime |
setCopy(String text,
Locale locale)
Sets this field in a copy of the DateTime to a parsed text value.
|
DateTime |
withMaximumValue()
Returns a new DateTime with this field set to the maximum value
for this field.
|
DateTime |
withMinimumValue()
Returns a new DateTime with this field set to the minimum value
for this field.
|
compareTo, compareTo, equals, get, getAsShortText, getAsShortText, getAsString, getAsText, getAsText, getDifference, getDifferenceAsLong, getDurationField, getFieldType, getLeapAmount, getLeapDurationField, getMaximumShortTextLength, getMaximumTextLength, getMaximumValue, getMaximumValueOverall, getMinimumValue, getMinimumValueOverall, getName, getRangeDurationField, hashCode, isLeap, remainder, toInterval, toString
public DateTimeField getField()
getField
in class AbstractReadableInstantFieldProperty
protected long getMillis()
getMillis
in class AbstractReadableInstantFieldProperty
protected Chronology getChronology()
getChronology
in class AbstractReadableInstantFieldProperty
public DateTime getDateTime()
public DateTime addToCopy(int value)
The DateTime attached to this property is unchanged by this call. This operation is faster than converting a DateTime to a MutableDateTime and back again when setting one field. When setting multiple fields, it is generally quicker to make the conversion to MutableDateTime.
value
- the value to add to the field in the copyIllegalArgumentException
- if the value isn't validpublic DateTime addToCopy(long value)
The DateTime attached to this property is unchanged by this call. This operation is faster than converting a DateTime to a MutableDateTime and back again when setting one field. When setting multiple fields, it is generally quicker to make the conversion to MutableDateTime.
value
- the value to add to the field in the copyIllegalArgumentException
- if the value isn't validpublic DateTime addWrapFieldToCopy(int value)
The DateTime attached to this property is unchanged by this call. This operation is faster than converting a DateTime to a MutableDateTime and back again when setting one field. When setting multiple fields, it is generally quicker to make the conversion to MutableDateTime.
value
- the value to add to the field in the copyIllegalArgumentException
- if the value isn't validpublic DateTime setCopy(int value)
The DateTime attached to this property is unchanged by this call. This operation is faster than converting a DateTime to a MutableDateTime and back again when setting one field. When setting multiple fields, it is generally quicker to make the conversion to MutableDateTime.
value
- the value to set the field in the copy toIllegalArgumentException
- if the value isn't validpublic DateTime setCopy(String text, Locale locale)
The DateTime attached to this property is unchanged by this call. This operation is faster than converting a DateTime to a MutableDateTime and back again when setting one field. When setting multiple fields, it is generally quicker to make the conversion to MutableDateTime.
text
- the text value to setlocale
- optional locale to use for selecting a text symbolIllegalArgumentException
- if the text value isn't validpublic DateTime setCopy(String text)
The DateTime attached to this property is unchanged by this call. This operation is faster than converting a DateTime to a MutableDateTime and back again when setting one field. When setting multiple fields, it is generally quicker to make the conversion to MutableDateTime.
text
- the text value to setIllegalArgumentException
- if the text value isn't validpublic DateTime withMaximumValue()
This operation is useful for obtaining a DateTime on the last day of the month, as month lengths vary.
DateTime lastDayOfMonth = dt.dayOfMonth().withMaximumValue();
The DateTime attached to this property is unchanged by this call.
public DateTime withMinimumValue()
The DateTime attached to this property is unchanged by this call.
public DateTime roundFloorCopy()
public DateTime roundCeilingCopy()
public DateTime roundHalfFloorCopy()
public DateTime roundHalfCeilingCopy()
public DateTime roundHalfEvenCopy()
Copyright © 2012 JBoss by Red Hat. All Rights Reserved.