public static final class LocalDateTime.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).
LocalDateTime dt = new LocalDateTime(1972, 12, 3, 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 LocalDateTime - they do not modify the original. The example below yields two independent immutable date objects 20 years apart.
LocalDateTime dt = new LocalDateTime(1972, 12, 3, 0, 0); LocalDateTime dt1920 = dt.year().setCopy(1920);
LocalDateTime.Property itself is thread-safe and immutable, as well as the LocalDateTime being operated on.
Modifier and Type | Method and Description |
---|---|
LocalDateTime |
addToCopy(int value)
Adds to this field in a copy of this LocalDateTime.
|
LocalDateTime |
addToCopy(long value)
Adds to this field in a copy of this LocalDateTime.
|
LocalDateTime |
addWrapFieldToCopy(int value)
Adds to this field, possibly wrapped, in a copy of this LocalDateTime.
|
DateTimeField |
getField()
Gets the field being used.
|
LocalDateTime |
getLocalDateTime()
Gets the LocalDateTime object linked to this property.
|
LocalDateTime |
roundCeilingCopy()
Rounds to the highest whole unit of this field on a copy of this
LocalDateTime.
|
LocalDateTime |
roundFloorCopy()
Rounds to the lowest whole unit of this field on a copy of this
LocalDateTime.
|
LocalDateTime |
roundHalfCeilingCopy()
Rounds to the nearest whole unit of this field on a copy of this
LocalDateTime, favoring the ceiling if halfway.
|
LocalDateTime |
roundHalfEvenCopy()
Rounds to the nearest whole unit of this field on a copy of this
LocalDateTime.
|
LocalDateTime |
roundHalfFloorCopy()
Rounds to the nearest whole unit of this field on a copy of this
LocalDateTime, favoring the floor if halfway.
|
LocalDateTime |
setCopy(int value)
Sets this field in a copy of the LocalDateTime.
|
LocalDateTime |
setCopy(java.lang.String text)
Sets this field in a copy of the LocalDateTime to a parsed text value.
|
LocalDateTime |
setCopy(java.lang.String text,
java.util.Locale locale)
Sets this field in a copy of the LocalDateTime to a parsed text value.
|
LocalDateTime |
withMaximumValue()
Returns a new LocalDateTime with this field set to the maximum value
for this field.
|
LocalDateTime |
withMinimumValue()
Returns a new LocalDateTime 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
public LocalDateTime getLocalDateTime()
public LocalDateTime addToCopy(int value)
The LocalDateTime attached to this property is unchanged by this call.
value
- the value to add to the field in the copyjava.lang.IllegalArgumentException
- if the value isn't validpublic LocalDateTime addToCopy(long value)
The LocalDateTime attached to this property is unchanged by this call.
value
- the value to add to the field in the copyjava.lang.IllegalArgumentException
- if the value isn't validpublic LocalDateTime addWrapFieldToCopy(int value)
The LocalDateTime attached to this property is unchanged by this call.
value
- the value to add to the field in the copyjava.lang.IllegalArgumentException
- if the value isn't validpublic LocalDateTime setCopy(int value)
The LocalDateTime attached to this property is unchanged by this call.
value
- the value to set the field in the copy tojava.lang.IllegalArgumentException
- if the value isn't validpublic LocalDateTime setCopy(java.lang.String text, java.util.Locale locale)
The LocalDateTime attached to this property is unchanged by this call.
text
- the text value to setlocale
- optional locale to use for selecting a text symboljava.lang.IllegalArgumentException
- if the text value isn't validpublic LocalDateTime setCopy(java.lang.String text)
The LocalDateTime attached to this property is unchanged by this call.
text
- the text value to setjava.lang.IllegalArgumentException
- if the text value isn't validpublic LocalDateTime withMaximumValue()
This operation is useful for obtaining a LocalDateTime on the last day of the month, as month lengths vary.
LocalDateTime lastDayOfMonth = dt.dayOfMonth().withMaximumValue();
The LocalDateTime attached to this property is unchanged by this call.
public LocalDateTime withMinimumValue()
The LocalDateTime attached to this property is unchanged by this call.
public LocalDateTime roundFloorCopy()
For example, rounding floor on the hourOfDay field of a LocalDateTime where the time is 10:30 would result in new LocalDateTime with the time of 10:00.
public LocalDateTime roundCeilingCopy()
For example, rounding floor on the hourOfDay field of a LocalDateTime where the time is 10:30 would result in new LocalDateTime with the time of 11:00.
public LocalDateTime roundHalfFloorCopy()
public LocalDateTime roundHalfCeilingCopy()
public LocalDateTime roundHalfEvenCopy()
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"