DateTime.Property binds a DateTime 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).
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 {@link org.joda.time.MutableDateTime MutableDateTime} class.
DateTime.Propery itself is thread-safe and immutable, as well as the DateTime being operated on.
@author Stephen Colebourne
@author Brian S O'Neill
@since 1.0