public static final class

LocalDateTime.Property

extends AbstractReadableInstantFieldProperty
java.lang.Object
   ↳ org.joda.time.field.AbstractReadableInstantFieldProperty
     ↳ org.joda.time.LocalDateTime.Property

Class Overview

LocalDateTime.Property binds a LocalDateTime to a DateTimeField allowing powerful datetime functionality to be easily accessed.

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.

Summary

Public Methods
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(String text, Locale locale)
Sets this field in a copy of the LocalDateTime to a parsed text value.
LocalDateTime setCopy(int value)
Sets this field in a copy of the LocalDateTime.
LocalDateTime setCopy(String text)
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.
Protected Methods
Chronology getChronology()
Gets the chronology of the datetime that this property is linked to.
long getMillis()
Gets the milliseconds of the datetime that this property is linked to.
[Expand]
Inherited Methods
From class org.joda.time.field.AbstractReadableInstantFieldProperty
From class java.lang.Object

Public Methods

public LocalDateTime addToCopy (int value)

Adds to this field in a copy of this LocalDateTime.

The LocalDateTime attached to this property is unchanged by this call.

Parameters
value the value to add to the field in the copy
Returns
  • a copy of the LocalDateTime with the field value changed
Throws
IllegalArgumentException if the value isn't valid

public LocalDateTime addToCopy (long value)

Adds to this field in a copy of this LocalDateTime.

The LocalDateTime attached to this property is unchanged by this call.

Parameters
value the value to add to the field in the copy
Returns
  • a copy of the LocalDateTime with the field value changed
Throws
IllegalArgumentException if the value isn't valid

public LocalDateTime addWrapFieldToCopy (int value)

Adds to this field, possibly wrapped, in a copy of this LocalDateTime. A field wrapped operation only changes this field. Thus 31st January addWrapField one day goes to the 1st January.

The LocalDateTime attached to this property is unchanged by this call.

Parameters
value the value to add to the field in the copy
Returns
  • a copy of the LocalDateTime with the field value changed
Throws
IllegalArgumentException if the value isn't valid

public DateTimeField getField ()

Gets the field being used.

Returns
  • the field

public LocalDateTime getLocalDateTime ()

Gets the LocalDateTime object linked to this property.

Returns
  • the linked LocalDateTime

public LocalDateTime roundCeilingCopy ()

Rounds to the highest whole unit of this field on a copy of this LocalDateTime.

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.

Returns
  • a copy of the LocalDateTime with the field value changed

public LocalDateTime roundFloorCopy ()

Rounds to the lowest whole unit of this field on a copy of this LocalDateTime.

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.

Returns
  • a copy of the LocalDateTime with the field value changed

public LocalDateTime roundHalfCeilingCopy ()

Rounds to the nearest whole unit of this field on a copy of this LocalDateTime, favoring the ceiling if halfway.

Returns
  • a copy of the LocalDateTime with the field value changed

public LocalDateTime roundHalfEvenCopy ()

Rounds to the nearest whole unit of this field on a copy of this LocalDateTime. If halfway, the ceiling is favored over the floor only if it makes this field's value even.

Returns
  • a copy of the LocalDateTime with the field value changed

public LocalDateTime roundHalfFloorCopy ()

Rounds to the nearest whole unit of this field on a copy of this LocalDateTime, favoring the floor if halfway.

Returns
  • a copy of the LocalDateTime with the field value changed

public LocalDateTime setCopy (String text, Locale locale)

Sets this field in a copy of the LocalDateTime to a parsed text value.

The LocalDateTime attached to this property is unchanged by this call.

Parameters
text the text value to set
locale optional locale to use for selecting a text symbol
Returns
  • a copy of the LocalDateTime with the field value changed
Throws
IllegalArgumentException if the text value isn't valid

public LocalDateTime setCopy (int value)

Sets this field in a copy of the LocalDateTime.

The LocalDateTime attached to this property is unchanged by this call.

Parameters
value the value to set the field in the copy to
Returns
  • a copy of the LocalDateTime with the field value changed
Throws
IllegalArgumentException if the value isn't valid

public LocalDateTime setCopy (String text)

Sets this field in a copy of the LocalDateTime to a parsed text value.

The LocalDateTime attached to this property is unchanged by this call.

Parameters
text the text value to set
Returns
  • a copy of the LocalDateTime with the field value changed
Throws
IllegalArgumentException if the text value isn't valid

public LocalDateTime withMaximumValue ()

Returns a new LocalDateTime with this field set to the maximum value for this field.

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.

Returns
  • a copy of the LocalDateTime with this field set to its maximum

public LocalDateTime withMinimumValue ()

Returns a new LocalDateTime with this field set to the minimum value for this field.

The LocalDateTime attached to this property is unchanged by this call.

Returns
  • a copy of the LocalDateTime with this field set to its minimum

Protected Methods

protected Chronology getChronology ()

Gets the chronology of the datetime that this property is linked to.

Returns
  • the chronology

protected long getMillis ()

Gets the milliseconds of the datetime that this property is linked to.

Returns
  • the milliseconds