Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    *  Copyright 2001-2011 Stephen Colebourne
    *
    *  Licensed under the Apache License, Version 2.0 (the "License");
    *  you may not use this file except in compliance with the License.
    *  You may obtain a copy of the License at
    *
    *      http://www.apache.org/licenses/LICENSE-2.0
    *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.joda.time;
  
  import java.util.Date;
  import java.util.HashSet;
  import java.util.Locale;
  import java.util.Set;
  
  import  org.joda.convert.FromString;
  import  org.joda.convert.ToString;
LocalDate is an immutable datetime class representing a date without a time zone.

LocalDate implements the ReadablePartial interface. To do this, the interface methods focus on the key fields - Year, MonthOfYear and DayOfMonth. However, all date fields may in fact be queried.

LocalDate differs from DateMidnight in that this class does not have a time zone and does not represent a single instant in time.

Calculations on LocalDate are performed using a Chronology. This chronology will be set internally to be in the UTC time zone for all calculations.

Each individual field can be queried in two ways:

  • getMonthOfYear()
  • monthOfYear().get()
The second technique also provides access to other useful methods on the field:
  • numeric value
  • text value
  • short text value
  • maximum/minimum values
  • add/subtract
  • set
  • rounding

LocalDate is thread-safe and immutable, provided that the Chronology is as well. All standard Chronology classes supplied are thread-safe and immutable.

Author(s):
Stephen Colebourne
Since:
1.3
  
  public final class LocalDate
          extends BaseLocal
          implements ReadablePartialSerializable {

    
Serialization lock
  
      private static final long serialVersionUID = -8775358157899L;

    
The index of the year field in the field array
  
      private static final int YEAR = 0;
    
The index of the monthOfYear field in the field array
  
      private static final int MONTH_OF_YEAR = 1;
    
The index of the dayOfMonth field in the field array
  
      private static final int DAY_OF_MONTH = 2;
    
Set of known duration types.
  
      private static final Set<DurationFieldTypeDATE_DURATION_TYPES = new HashSet<DurationFieldType>();
      static {
          .add(DurationFieldType.days());
          .add(DurationFieldType.weeks());
          .add(DurationFieldType.months());
         .add(DurationFieldType.weekyears());
         .add(DurationFieldType.years());
         .add(DurationFieldType.centuries());
         // eras are supported, although the DurationField generally isn't
         .add(DurationFieldType.eras());
     }

    
The local millis from 1970-01-01T00:00:00
 
     private final long iLocalMillis;
    
The chronology to use in UTC.
 
     private final Chronology iChronology;
    
The cached hash code.
 
     private transient volatile int iHash;
 
     //-----------------------------------------------------------------------
     
Obtains a LocalDate set to the current system millisecond time using ISOChronology in the default time zone.

Returns:
the current date-time, not null
Since:
2.0
 
     public static LocalDate now() {
         return new LocalDate();
     }

    
Obtains a LocalDate set to the current system millisecond time using ISOChronology in the specified time zone.

Parameters:
zone the time zone, not null
Returns:
the current date-time, not null
Since:
2.0
 
     public static LocalDate now(DateTimeZone zone) {
         if (zone == null) {
             throw new NullPointerException("Zone must not be null");
         }
         return new LocalDate(zone);
     }

    
Obtains a LocalDate set to the current system millisecond time using the specified chronology.

Parameters:
chronology the chronology, not null
Returns:
the current date-time, not null
Since:
2.0
 
     public static LocalDate now(Chronology chronology) {
         if (chronology == null) {
             throw new NullPointerException("Chronology must not be null");
         }
         return new LocalDate(chronology);
     }
 
     //-----------------------------------------------------------------------
     
Parses a LocalDate from the specified string.

This uses ISODateTimeFormat.localDateParser().

Parameters:
str the string to parse, not null
Since:
2.0
 
     @FromString
     public static LocalDate parse(String str) {
         return parse(str, ISODateTimeFormat.localDateParser());
     }

    
Parses a LocalDate from the specified string using a formatter.

Parameters:
str the string to parse, not null
formatter the formatter to use, not null
Since:
2.0
 
     public static LocalDate parse(String strDateTimeFormatter formatter) {
         return formatter.parseLocalDate(str);
     }
 
     //-----------------------------------------------------------------------
     
Constructs a LocalDate from a java.util.Calendar using exactly the same field values.

Each field is queried from the Calendar and assigned to the LocalDate. This is useful if you have been using the Calendar as a local date, ignoring the zone.

One advantage of this method is that this method is unaffected if the version of the time zone data differs between the JDK and Joda-Time. That is because the local field values are transferred, calculated using the JDK time zone data and without using the Joda-Time time zone data.

This factory method ignores the type of the calendar and always creates a LocalDate with ISO chronology. It is expected that you will only pass in instances of GregorianCalendar however this is not validated.

Parameters:
calendar the Calendar to extract fields from
Returns:
the created LocalDate
Throws:
IllegalArgumentException if the calendar is null
IllegalArgumentException if the date is invalid for the ISO chronology
 
     public static LocalDate fromCalendarFields(Calendar calendar) {
         if (calendar == null) {
             throw new IllegalArgumentException("The calendar must not be null");
         }
         return new LocalDate(
             calendar.get(.),
             calendar.get(.) + 1,
             calendar.get(.)
         );
     }

    
Constructs a LocalDate from a java.util.Date using exactly the same field values.

Each field is queried from the Date and assigned to the LocalDate. This is useful if you have been using the Date as a local date, ignoring the zone.

One advantage of this method is that this method is unaffected if the version of the time zone data differs between the JDK and Joda-Time. That is because the local field values are transferred, calculated using the JDK time zone data and without using the Joda-Time time zone data.

This factory method always creates a LocalDate with ISO chronology.

Parameters:
date the Date to extract fields from
Returns:
the created LocalDate
Throws:
IllegalArgumentException if the calendar is null
IllegalArgumentException if the date is invalid for the ISO chronology
 
     @SuppressWarnings("deprecation")
     public static LocalDate fromDateFields(Date date) {
         if (date == null) {
             throw new IllegalArgumentException("The date must not be null");
         }
         return new LocalDate(
             date.getYear() + 1900,
             date.getMonth() + 1,
             date.getDate()
         );
     }
 
     //-----------------------------------------------------------------------
     
Constructs an instance set to the current local time evaluated using ISO chronology in the default zone.

Once the constructor is completed, the zone is no longer used.

See also:
now()
 
     public LocalDate() {
         this(DateTimeUtils.currentTimeMillis(), ISOChronology.getInstance());
     }

    
Constructs an instance set to the current local time evaluated using ISO chronology in the specified zone.

If the specified time zone is null, the default zone is used. Once the constructor is completed, the zone is no longer used.

Parameters:
zone the time zone, null means default zone
See also:
now(DateTimeZone)
 
     public LocalDate(DateTimeZone zone) {
         this(DateTimeUtils.currentTimeMillis(), ISOChronology.getInstance(zone));
     }

    
Constructs an instance set to the current local time evaluated using specified chronology.

If the chronology is null, ISO chronology in the default time zone is used. Once the constructor is completed, the zone is no longer used.

Parameters:
chronology the chronology, null means ISOChronology in default zone
See also:
now(Chronology)
 
     public LocalDate(Chronology chronology) {
         this(DateTimeUtils.currentTimeMillis(), chronology);
     }
 
     //-----------------------------------------------------------------------
     
Constructs an instance set to the local time defined by the specified instant evaluated using ISO chronology in the default zone.

Once the constructor is completed, the zone is no longer used.

Parameters:
instant the milliseconds from 1970-01-01T00:00:00Z
 
     public LocalDate(long instant) {
         this(instant, ISOChronology.getInstance());
     }

    
Constructs an instance set to the local time defined by the specified instant evaluated using ISO chronology in the specified zone.

If the specified time zone is null, the default zone is used. Once the constructor is completed, the zone is no longer used.

Parameters:
instant the milliseconds from 1970-01-01T00:00:00Z
zone the time zone, null means default zone
 
     public LocalDate(long instantDateTimeZone zone) {
         this(instant, ISOChronology.getInstance(zone));
     }

    
Constructs an instance set to the local time defined by the specified instant evaluated using the specified chronology.

If the chronology is null, ISO chronology in the default zone is used. Once the constructor is completed, the zone is no longer used.

Parameters:
instant the milliseconds from 1970-01-01T00:00:00Z
chronology the chronology, null means ISOChronology in default zone
 
     public LocalDate(long instantChronology chronology) {
         chronology = DateTimeUtils.getChronology(chronology);
         
         long localMillis = chronology.getZone().getMillisKeepLocal(.instant);
         chronology = chronology.withUTC();
          = chronology.dayOfMonth().roundFloor(localMillis);
          = chronology;
     }
 
     //-----------------------------------------------------------------------
     
Constructs an instance from an Object that represents a datetime. The time zone will be retrieved from the object if possible, otherwise the default time zone will be used.

If the object contains no chronology, ISOChronology is used. Once the constructor is completed, the zone is no longer used.

The recognised object types are defined in ConverterManager and include ReadablePartial, ReadableInstant, String, Calendar and Date. The String formats are described by ISODateTimeFormat.localDateParser(). The default String converter ignores the zone and only parses the field values.

Parameters:
instant the datetime object
Throws:
IllegalArgumentException if the instant is invalid
 
     public LocalDate(Object instant) {
         this(instant, (Chronologynull);
     }

    
Constructs an instance from an Object that represents a datetime, forcing the time zone to that specified.

If the object contains no chronology, ISOChronology is used. If the specified time zone is null, the default zone is used. Once the constructor is completed, the zone is no longer used.

The recognised object types are defined in ConverterManager and include ReadablePartial, ReadableInstant, String, Calendar and Date. The String formats are described by ISODateTimeFormat.localDateParser(). The default String converter ignores the zone and only parses the field values.

Parameters:
instant the datetime object
zone the time zone
Throws:
IllegalArgumentException if the instant is invalid
 
     public LocalDate(Object instantDateTimeZone zone) {
         PartialConverter converter = ConverterManager.getInstance().getPartialConverter(instant);
         Chronology chronology = converter.getChronology(instantzone);
         chronology = DateTimeUtils.getChronology(chronology);
          = chronology.withUTC();
         int[] values = converter.getPartialValues(thisinstantchronology, ISODateTimeFormat.localDateParser());
          = .getDateTimeMillis(values[0], values[1], values[2], 0);
     }

    
Constructs an instance from an Object that represents a datetime, using the specified chronology.

If the chronology is null, ISO in the default time zone is used. Once the constructor is completed, the zone is no longer used.

The recognised object types are defined in ConverterManager and include ReadablePartial, ReadableInstant, String, Calendar and Date. The String formats are described by ISODateTimeFormat.localDateParser(). The default String converter ignores the zone and only parses the field values.

Parameters:
instant the datetime object
chronology the chronology
Throws:
IllegalArgumentException if the instant is invalid
 
     public LocalDate(Object instantChronology chronology) {
         PartialConverter converter = ConverterManager.getInstance().getPartialConverter(instant);
         chronology = converter.getChronology(instantchronology);
         chronology = DateTimeUtils.getChronology(chronology);
          = chronology.withUTC();
         int[] values = converter.getPartialValues(thisinstantchronology, ISODateTimeFormat.localDateParser());
          = .getDateTimeMillis(values[0], values[1], values[2], 0);
     }
 
     //-----------------------------------------------------------------------
     
Constructs an instance set to the specified date and time using ISOChronology.

Parameters:
year the year
monthOfYear the month of the year
dayOfMonth the day of the month
 
     public LocalDate(
             int year,
             int monthOfYear,
             int dayOfMonth) {
         this(yearmonthOfYeardayOfMonth, ISOChronology.getInstanceUTC());
     }

    
Constructs an instance set to the specified date and time using the specified chronology, whose zone is ignored.

If the chronology is null, ISOChronology is used.

Parameters:
year the year
monthOfYear the month of the year
dayOfMonth the day of the month
chronology the chronology, null means ISOChronology in default zone
 
     public LocalDate(
             int year,
             int monthOfYear,
             int dayOfMonth,
             Chronology chronology) {
         super();
         chronology = DateTimeUtils.getChronology(chronology).withUTC();
         long instant = chronology.getDateTimeMillis(yearmonthOfYeardayOfMonth, 0);
          = chronology;
          = instant;
     }

    
Handle broken serialization from other tools.

Returns:
the resolved object, not null
 
     private Object readResolve() {
         if ( == null) {
             return new LocalDate(, ISOChronology.getInstanceUTC());
         }
         if (..equals(.getZone()) == false) {
             return new LocalDate(.withUTC());
         }
         return this;
     }
 
     //-----------------------------------------------------------------------
     
Gets the number of fields in this partial, which is three. The supported fields are Year, MonthOfYear and DayOfMonth. Note that all fields from day and above may in fact be queried via other methods.

Returns:
the field count, three
 
     public int size() {
         return 3;
     }

    
Gets the field for a specific index in the chronology specified.

This method must not use any instance variables.

Parameters:
index the index to retrieve
chrono the chronology to use
Returns:
the field
 
     protected DateTimeField getField(int indexChronology chrono) {
         switch (index) {
             case :
                 return chrono.year();
             case :
                 return chrono.monthOfYear();
             case :
                 return chrono.dayOfMonth();
             default:
                 throw new IndexOutOfBoundsException("Invalid index: " + index);
         }
     }

    
Gets the value of the field at the specifed index.

This method is required to support the ReadablePartial interface. The supported fields are Year, MonthOfYear and DayOfMonth. Note that all fields from day and above may in fact be queried via other methods.

Parameters:
index the index, zero to two
Returns:
the value
Throws:
IndexOutOfBoundsException if the index is invalid
 
     public int getValue(int index) {
         switch (index) {
             case :
                 return getChronology().year().get(getLocalMillis());
             case :
                 return getChronology().monthOfYear().get(getLocalMillis());
             case :
                 return getChronology().dayOfMonth().get(getLocalMillis());
             default:
                 throw new IndexOutOfBoundsException("Invalid index: " + index);
         }
     }
 
     //-----------------------------------------------------------------------
     
Get the value of one of the fields of a datetime.

This method gets the value of the specified field. For example:

 LocalDate dt = LocalDate.nowDefaultZone();
 int year = dt.get(DateTimeFieldType.year());
 

Parameters:
fieldType a field type, usually obtained from DateTimeFieldType, not null
Returns:
the value of that field
Throws:
IllegalArgumentException if the field type is null or unsupported
 
     public int get(DateTimeFieldType fieldType) {
         if (fieldType == null) {
             throw new IllegalArgumentException("The DateTimeFieldType must not be null");
         }
         if (isSupported(fieldType) == false) {
             throw new IllegalArgumentException("Field '" + fieldType + "' is not supported");
         }
         return fieldType.getField(getChronology()).get(getLocalMillis());
     }

    
Checks if the field type specified is supported by this local date and chronology. This can be used to avoid exceptions in get(DateTimeFieldType).

Parameters:
type a field type, usually obtained from DateTimeFieldType
Returns:
true if the field type is supported
 
     public boolean isSupported(DateTimeFieldType type) {
         if (type == null) {
             return false;
         }
         DurationFieldType durType = type.getDurationType();
         if (.contains(durType) ||
                 durType.getField(getChronology()).getUnitMillis() >=
                     getChronology().days().getUnitMillis()) {
             return type.getField(getChronology()).isSupported();
         }
         return false;
     }

    
Checks if the duration type specified is supported by this local date and chronology.

Parameters:
type a duration type, usually obtained from DurationFieldType
Returns:
true if the field type is supported
 
     public boolean isSupported(DurationFieldType type) {
         if (type == null) {
             return false;
         }
         DurationField field = type.getField(getChronology());
         if (.contains(type) ||
             field.getUnitMillis() >= getChronology().days().getUnitMillis()) {
             return field.isSupported();
         }
         return false;
     }
 
     //-----------------------------------------------------------------------
     
Gets the local milliseconds from the Java epoch of 1970-01-01T00:00:00 (not fixed to any specific time zone).

Returns:
the number of milliseconds since 1970-01-01T00:00:00
Since:
1.5 (previously private)
 
     protected long getLocalMillis() {
         return ;
     }

    
Gets the chronology of the date.

Returns:
the Chronology that the date is using
 
     public Chronology getChronology() {
         return ;
     }
 
     //-----------------------------------------------------------------------
     
Compares this ReadablePartial with another returning true if the chronology, field types and values are equal.

Parameters:
partial an object to check against
Returns:
true if fields and values are equal
 
     public boolean equals(Object partial) {
         // override to perform faster
         if (this == partial) {
             return true;
         }
         if (partial instanceof LocalDate) {
             LocalDate other = (LocalDatepartial;
             if (.equals(other.iChronology)) {
                 return  == other.iLocalMillis;
             }
         }
         return super.equals(partial);
     }

    
Gets a hash code for the instant as defined in ReadablePartial.

Returns:
a suitable hash code
 
     public int hashCode() {
         // override for performance
         int hash = ;
         if (hash == 0) {
             hash =  = super.hashCode();
         }
         return hash;
     }

    
Compares this partial with another returning an integer indicating the order.

The fields are compared in order, from largest to smallest. The first field that is non-equal is used to determine the result.

The specified object must be a partial instance whose field types match those of this partial.

Parameters:
partial an object to check against
Returns:
negative if this is less, zero if equal, positive if greater
Throws:
ClassCastException if the partial is the wrong class or if it has field types that don't match
NullPointerException if the partial is null
 
     public int compareTo(ReadablePartial partial) {
         // override to perform faster
         if (this == partial) {
             return 0;
         }
         if (partial instanceof LocalDate) {
             LocalDate other = (LocalDatepartial;
             if (.equals(other.iChronology)) {
                 return ( < other.iLocalMillis ? -1 :
                             ( == other.iLocalMillis ? 0 : 1));
 
             }
         }
         return super.compareTo(partial);
     }
 
     //-----------------------------------------------------------------------
     
Converts this LocalDate to a full datetime at the earliest valid time for the date using the default time zone.

The time will normally be midnight, as that is the earliest time on any given day. However, in some time zones when Daylight Savings Time starts, there is no midnight because time jumps from 11:59 to 01:00. This method handles that situation by returning 01:00 on that date.

This instance is immutable and unaffected by this method call.

Returns:
this date as a datetime at the start of the day
Since:
1.5
 
     public DateTime toDateTimeAtStartOfDay() {
         return toDateTimeAtStartOfDay(null);
     }

    
Converts this LocalDate to a full datetime at the earliest valid time for the date using the specified time zone.

The time will normally be midnight, as that is the earliest time on any given day. However, in some time zones when Daylight Savings Time starts, there is no midnight because time jumps from 11:59 to 01:00. This method handles that situation by returning 01:00 on that date.

This method uses the chronology from this instance plus the time zone specified.

This instance is immutable and unaffected by this method call.

Parameters:
zone the zone to use, null means default zone
Returns:
this date as a datetime at the start of the day
Since:
1.5
 
     public DateTime toDateTimeAtStartOfDay(DateTimeZone zone) {
         zone = DateTimeUtils.getZone(zone);
         Chronology chrono = getChronology().withZone(zone);
         long localMillis = getLocalMillis() + 6L * .;
         long instant = zone.convertLocalToUTC(localMillisfalse);
         instant = chrono.dayOfMonth().roundFloor(instant);
         return new DateTime(instantchrono);
     }
 
     //-----------------------------------------------------------------------
     
Converts this LocalDate to a full datetime at midnight using the default time zone.

This method will throw an exception if the default time zone switches to Daylight Savings Time at midnight and this LocalDate represents that switchover date. The problem is that there is no such time as midnight on the required date, and as such an exception is thrown.

This instance is immutable and unaffected by this method call.

Deprecated:
Use toDateTimeAtStartOfDay() which won't throw an exception
Returns:
this date as a datetime at midnight
 
     @Deprecated
     public DateTime toDateTimeAtMidnight() {
         return toDateTimeAtMidnight(null);
     }

    
Converts this LocalDate to a full datetime at midnight using the specified time zone.

This method will throw an exception if the time zone switches to Daylight Savings Time at midnight and this LocalDate represents that switchover date. The problem is that there is no such time as midnight on the required date, and as such an exception is thrown.

This method uses the chronology from this instance plus the time zone specified.

This instance is immutable and unaffected by this method call.

Deprecated:
Use toDateTimeAtStartOfDay(DateTimeZone) which won't throw an exception
Parameters:
zone the zone to use, null means default zone
Returns:
this date as a datetime at midnight
 
     @Deprecated
     public DateTime toDateTimeAtMidnight(DateTimeZone zone) {
         zone = DateTimeUtils.getZone(zone);
         Chronology chrono = getChronology().withZone(zone);
         return new DateTime(getYear(), getMonthOfYear(), getDayOfMonth(), 0, 0, 0, 0, chrono);
     }
 
     //-----------------------------------------------------------------------
     
Converts this LocalDate to a full datetime using the default time zone setting the date fields from this instance and the time fields from the current time.

This method will throw an exception if the datetime that would be created does not exist when the time zone is taken into account.

This instance is immutable and unaffected by this method call.

Returns:
this date as a datetime with the time as the current time
 
     public DateTime toDateTimeAtCurrentTime() {
         return toDateTimeAtCurrentTime(null);
     }

    
Converts this LocalDate 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.

This method will throw an exception if the datetime that would be created does not exist when the time zone is taken into account.

This instance is immutable and unaffected by this method call.

Parameters:
zone the zone to use, null means default zone
Returns:
this date as a datetime with the time as the current time
 
     public DateTime toDateTimeAtCurrentTime(DateTimeZone zone) {
         zone = DateTimeUtils.getZone(zone);
         Chronology chrono = getChronology().withZone(zone);
         long instantMillis = DateTimeUtils.currentTimeMillis();
         long resolved = chrono.set(thisinstantMillis);
         return new DateTime(resolvedchrono);
     }
 
     //-----------------------------------------------------------------------
     
Converts this LocalDate to a DateMidnight in the default time zone.

As from v1.5, you are recommended to avoid DateMidnight and use toDateTimeAtStartOfDay() instead because of the exception detailed below.

This method will throw an exception if the default time zone switches to Daylight Savings Time at midnight and this LocalDate represents that switchover date. The problem is that there is no such time as midnight on the required date, and as such an exception is thrown.

This instance is immutable and unaffected by this method call.

Returns:
the DateMidnight instance in the default zone
 
     public DateMidnight toDateMidnight() {
         return toDateMidnight(null);
     }

    
Converts this LocalDate to a DateMidnight.

As from v1.5, you are recommended to avoid DateMidnight and use toDateTimeAtStartOfDay() instead because of the exception detailed below.

This method will throw an exception if the time zone switches to Daylight Savings Time at midnight and this LocalDate represents that switchover date. The problem is that there is no such time as midnight on the required date, and as such an exception is thrown.

This instance is immutable and unaffected by this method call.

Parameters:
zone the zone to get the DateMidnight in, null means default zone
Returns:
the DateMidnight instance
 
     public DateMidnight toDateMidnight(DateTimeZone zone) {
         zone = DateTimeUtils.getZone(zone);
         Chronology chrono = getChronology().withZone(zone);
         return new DateMidnight(getYear(), getMonthOfYear(), getDayOfMonth(), chrono);
     }
 
     //-----------------------------------------------------------------------
     
Converts this object to a LocalDateTime using a LocalTime to fill in the missing fields.

The resulting chronology is determined by the chronology of this LocalDate. The chronology of the time must also match. If the time is null an exception is thrown.

This instance is immutable and unaffected by this method call.

Parameters:
time the time of day to use, must not be null
Returns:
the LocalDateTime instance
Throws:
IllegalArgumentException if the time is null
IllegalArgumentException if the chronology of the time does not match
Since:
1.5
 
     public LocalDateTime toLocalDateTime(LocalTime time) {
         if (time == null) {
             throw new IllegalArgumentException("The time must not be null");
         }
         if (getChronology() != time.getChronology()) {
             throw new IllegalArgumentException("The chronology of the time does not match");
         }
         long localMillis = getLocalMillis() + time.getLocalMillis();
         return new LocalDateTime(localMillisgetChronology());
     }
 
     //-----------------------------------------------------------------------
     
Converts this object to a DateTime using a LocalTime to fill in the missing fields and using the default time zone.

The resulting chronology is determined by the chronology of this LocalDate. The chronology of the time must match. If the time is null, the current time in the date's chronology is used.

This method will throw an exception if the datetime that would be created does not exist when the time zone is taken into account.

This instance is immutable and unaffected by this method call.

Parameters:
time the time of day to use, null means current time
Returns:
the DateTime instance
Throws:
IllegalArgumentException if the chronology of the time does not match
 
     public DateTime toDateTime(LocalTime time) {
         return toDateTime(timenull);
     }

    
Converts this object to a DateTime using a LocalTime to fill in the missing fields.

The resulting chronology is determined by the chronology of this LocalDate plus the time zone. The chronology of the time must match. If the time is null, the current time in the date's chronology is used.

This method will throw an exception if the datetime that would be created does not exist when the time zone is taken into account.

This instance is immutable and unaffected by this method call.

Parameters:
time the time of day to use, null means current time
zone the zone to get the DateTime in, null means default
Returns:
the DateTime instance
Throws:
IllegalArgumentException if the chronology of the time does not match
 
     public DateTime toDateTime(LocalTime timeDateTimeZone zone) {
         if (time != null && getChronology() != time.getChronology()) {
             throw new IllegalArgumentException("The chronology of the time does not match");
         }
         Chronology chrono = getChronology().withZone(zone);
         long instant = DateTimeUtils.currentTimeMillis();
         instant = chrono.set(thisinstant);
         if (time != null) {
             instant = chrono.set(timeinstant);
         }
         return new DateTime(instantchrono);
     }
 
     //-----------------------------------------------------------------------
     
Converts this object to an Interval representing the whole day in the default time zone.

The interval may have more or less than 24 hours if this is a daylight savings cutover date.

This instance is immutable and unaffected by this method call.

Returns:
a interval over the day
 
     public Interval toInterval() {
         return toInterval(null);
     }

    
Converts this object to an Interval representing the whole day.

The interval may have more or less than 24 hours if this is a daylight savings cutover date.

This instance is immutable and unaffected by this method call.

Parameters:
zone the zone to get the Interval in, null means default
Returns:
a interval over the day
 
     public Interval toInterval(DateTimeZone zone) {
         zone = DateTimeUtils.getZone(zone);
         DateTime start = toDateTimeAtStartOfDay(zone);
         DateTime end = plusDays(1).toDateTimeAtStartOfDay(zone);
         return new Interval(startend);
     }
 
     //-----------------------------------------------------------------------
     
Get the date time as a java.util.Date.

The Date object created has exactly the same year, month and day as this date. The time will be set to the earliest valid time for that date.

Converting to a JDK Date is full of complications as the JDK Date constructor doesn't behave as you might expect around DST transitions. This method works by taking a first guess and then adjusting the JDK date until it has the earliest valid instant. This also handles the situation where the JDK time zone data differs from the Joda-Time time zone data.

Returns:
a Date initialised with this date, never null
Since:
2.0
 
     @SuppressWarnings("deprecation")
     public Date toDate() {
         int dom = getDayOfMonth();
         Date date = new Date(getYear() - 1900, getMonthOfYear() - 1, dom);
         LocalDate check = LocalDate.fromDateFields(date);
         if (check.isBefore(this)) {
             // DST gap (no midnight)
             // move forward in units of one hour until date correct
             while (check.equals(this) == false) {
                 date.setTime(date.getTime() + 3600000);
                 check = LocalDate.fromDateFields(date);
             }
             // move back in units of one second until date wrong
             while (date.getDate() == dom) {
                 date.setTime(date.getTime() - 1000);
             }
            // fix result
            date.setTime(date.getTime() + 1000);
        } else if (check.equals(this)) {
            // check for DST overlap (two midnights)
            Date earlier = new Date(date.getTime() - TimeZone.getDefault().getDSTSavings());
            if (earlier.getDate() == dom) {
                date = earlier;
            }
        }
        return date;
    }
    //-----------------------------------------------------------------------
    
Returns a copy of this date with different local millis.

The returned object will be a new instance of the same type. Only the millis will change, the chronology is kept. The returned object will be either be a new instance or this.

Parameters:
newMillis the new millis, from 1970-01-01T00:00:00
Returns:
a copy of this date with different millis
    LocalDate withLocalMillis(long newMillis) {
        newMillis = .dayOfMonth().roundFloor(newMillis);
        return (newMillis == getLocalMillis() ? this : new LocalDate(newMillisgetChronology()));
    }
    //-----------------------------------------------------------------------
    
Returns a copy of this date with the partial set of fields replacing those from this instance.

For example, if the partial contains a year and a month then those two fields will be changed in the returned instance. Unsupported fields are ignored. If the partial is null, then this is returned.

Parameters:
partial the partial set of fields to apply to this date, null ignored
Returns:
a copy of this date with a different set of fields
Throws:
IllegalArgumentException if any value is invalid
    public LocalDate withFields(ReadablePartial partial) {
        if (partial == null) {
            return this;
        }
        return withLocalMillis(getChronology().set(partialgetLocalMillis()));
    }

    
Returns a copy of this date with the specified field set to a new value.

For example, if the field type is monthOfYear then the month of year field will be changed in the returned instance. If the field type is null, then this is returned.

These two lines are equivalent:

 LocalDate updated = dt.withDayOfMonth(6);
 LocalDate updated = dt.withField(DateTimeFieldType.dayOfMonth(), 6);
 

Parameters:
fieldType the field type to set, not null
value the value to set
Returns:
a copy of this date with the field set
Throws:
IllegalArgumentException if the field is null or unsupported
    public LocalDate withField(DateTimeFieldType fieldTypeint value) {
        if (fieldType == null) {
            throw new IllegalArgumentException("Field must not be null");
        }
        if (isSupported(fieldType) == false) {
            throw new IllegalArgumentException("Field '" + fieldType + "' is not supported");
        }
        long instant = fieldType.getField(getChronology()).set(getLocalMillis(), value);
        return withLocalMillis(instant);
    }

    
Returns a copy of this date with the value of the specified field increased.

If the addition is zero or the field is null, then this is returned.

These three lines are equivalent:

 LocalDate added = dt.withFieldAdded(DurationFieldType.years(), 6);
 LocalDate added = dt.plusYears(6);
 LocalDate added = dt.plus(Period.years(6));
 

Parameters:
fieldType the field type to add to, not null
amount the amount to add
Returns:
a copy of this date with the field updated
Throws:
IllegalArgumentException if the field is null or unsupported
ArithmeticException if the result exceeds the internal capacity
    public LocalDate withFieldAdded(DurationFieldType fieldTypeint amount) {
        if (fieldType == null) {
            throw new IllegalArgumentException("Field must not be null");
        }
        if (isSupported(fieldType) == false) {
            throw new IllegalArgumentException("Field '" + fieldType + "' is not supported");
        }
        if (amount == 0) {
            return this;
        }
        long instant = fieldType.getField(getChronology()).add(getLocalMillis(), amount);
        return withLocalMillis(instant);
    }
    //-----------------------------------------------------------------------
    
Returns a copy of this date with the specified period added.

If the addition is zero, then this is returned.

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).

Unsupported time fields are ignored, thus adding a period of 24 hours will not have any effect.

Parameters:
period the period to add to this one, null means zero
scalar the amount of times to add, such as -1 to subtract once
Returns:
a copy of this date with the period added
Throws:
ArithmeticException if the result exceeds the internal capacity
    public LocalDate withPeriodAdded(ReadablePeriod periodint scalar) {
        if (period == null || scalar == 0) {
            return this;
        }
        long instant = getLocalMillis();
        Chronology chrono = getChronology();
        for (int i = 0; i < period.size(); i++) {
            long value = FieldUtils.safeMultiply(period.getValue(i), scalar);
            DurationFieldType type = period.getFieldType(i);
            if (isSupported(type)) {
                instant = type.getField(chrono).add(instantvalue);
            }
        }
        return withLocalMillis(instant);
    }
    //-----------------------------------------------------------------------
    
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).

Unsupported time fields are ignored, thus adding a period of 24 hours will not have any effect.

Parameters:
period the period to add to this one, null means zero
Returns:
a copy of this date with the period added
Throws:
ArithmeticException if the result exceeds the internal capacity
    public LocalDate plus(ReadablePeriod period) {
        return withPeriodAdded(period, 1);
    }
    //-----------------------------------------------------------------------
    
Returns a copy of this date plus the specified number of years.

This adds the specified number of years to the date. If adding years makes the day-of-month invalid, it is adjusted to the last valid day in the month. This LocalDate instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 LocalDate added = dt.plusYears(6);
 LocalDate added = dt.plus(Period.years(6));
 LocalDate added = dt.withFieldAdded(DurationFieldType.years(), 6);
 

Parameters:
years the amount of years to add, may be negative
Returns:
the new LocalDate plus the increased years
    public LocalDate plusYears(int years) {
        if (years == 0) {
            return this;
        }
        long instant = getChronology().years().add(getLocalMillis(), years);
        return withLocalMillis(instant);
    }

    
Returns a copy of this date plus the specified number of months.

This adds the specified number of months to the date. The addition may change the year, but the day-of-month is normally unchanged. If adding months makes the day-of-month invalid, it is adjusted to the last valid day in the month. This LocalDate instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 LocalDate added = dt.plusMonths(6);
 LocalDate added = dt.plus(Period.months(6));
 LocalDate added = dt.withFieldAdded(DurationFieldType.months(), 6);
 

Parameters:
months the amount of months to add, may be negative
Returns:
the new LocalDate plus the increased months
    public LocalDate plusMonths(int months) {
        if (months == 0) {
            return this;
        }
        long instant = getChronology().months().add(getLocalMillis(), months);
        return withLocalMillis(instant);
    }

    
Returns a copy of this date plus the specified number of weeks.

This LocalDate instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 LocalDate added = dt.plusWeeks(6);
 LocalDate added = dt.plus(Period.weeks(6));
 LocalDate added = dt.withFieldAdded(DurationFieldType.weeks(), 6);
 

Parameters:
weeks the amount of weeks to add, may be negative
Returns:
the new LocalDate plus the increased weeks
    public LocalDate plusWeeks(int weeks) {
        if (weeks == 0) {
            return this;
        }
        long instant = getChronology().weeks().add(getLocalMillis(), weeks);
        return withLocalMillis(instant);
    }

    
Returns a copy of this date plus the specified number of days.

This LocalDate instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 LocalDate added = dt.plusDays(6);
 LocalDate added = dt.plus(Period.days(6));
 LocalDate added = dt.withFieldAdded(DurationFieldType.days(), 6);
 

Parameters:
days the amount of days to add, may be negative
Returns:
the new LocalDate plus the increased days
    public LocalDate plusDays(int days) {
        if (days == 0) {
            return this;
        }
        long instant = getChronology().days().add(getLocalMillis(), days);
        return withLocalMillis(instant);
    }
    //-----------------------------------------------------------------------
    
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).

Unsupported time fields are ignored, thus subtracting a period of 24 hours will not have any effect.

Parameters:
period the period to reduce this instant by
Returns:
a copy of this LocalDate with the period taken away
Throws:
ArithmeticException if the result exceeds the internal capacity
    public LocalDate minus(ReadablePeriod period) {
        return withPeriodAdded(period, -1);
    }
    //-----------------------------------------------------------------------
    
Returns a copy of this date minus the specified number of years.

This subtracts the specified number of years from the date. If subtracting years makes the day-of-month invalid, it is adjusted to the last valid day in the month. This LocalDate instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 LocalDate subtracted = dt.minusYears(6);
 LocalDate subtracted = dt.minus(Period.years(6));
 LocalDate subtracted = dt.withFieldAdded(DurationFieldType.years(), -6);
 

Parameters:
years the amount of years to subtract, may be negative
Returns:
the new LocalDate minus the increased years
    public LocalDate minusYears(int years) {
        if (years == 0) {
            return this;
        }
        long instant = getChronology().years().subtract(getLocalMillis(), years);
        return withLocalMillis(instant);
    }

    
Returns a copy of this date minus the specified number of months.

This subtracts the specified number of months from the date. The subtraction may change the year, but the day-of-month is normally unchanged. If subtracting months makes the day-of-month invalid, it is adjusted to the last valid day in the month. This LocalDate instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 LocalDate subtracted = dt.minusMonths(6);
 LocalDate subtracted = dt.minus(Period.months(6));
 LocalDate subtracted = dt.withFieldAdded(DurationFieldType.months(), -6);
 

Parameters:
months the amount of months to subtract, may be negative
Returns:
the new LocalDate minus the increased months
    public LocalDate minusMonths(int months) {
        if (months == 0) {
            return this;
        }
        long instant = getChronology().months().subtract(getLocalMillis(), months);
        return withLocalMillis(instant);
    }

    
Returns a copy of this date minus the specified number of weeks.

This LocalDate instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 LocalDate subtracted = dt.minusWeeks(6);
 LocalDate subtracted = dt.minus(Period.weeks(6));
 LocalDate subtracted = dt.withFieldAdded(DurationFieldType.weeks(), -6);
 

Parameters:
weeks the amount of weeks to subtract, may be negative
Returns:
the new LocalDate minus the increased weeks
    public LocalDate minusWeeks(int weeks) {
        if (weeks == 0) {
            return this;
        }
        long instant = getChronology().weeks().subtract(getLocalMillis(), weeks);
        return withLocalMillis(instant);
    }

    
Returns a copy of this date minus the specified number of days.

This LocalDate instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 LocalDate subtracted = dt.minusDays(6);
 LocalDate subtracted = dt.minus(Period.days(6));
 LocalDate subtracted = dt.withFieldAdded(DurationFieldType.days(), -6);
 

Parameters:
days the amount of days to subtract, may be negative
Returns:
the new LocalDate minus the increased days
    public LocalDate minusDays(int days) {
        if (days == 0) {
            return this;
        }
        long instant = getChronology().days().subtract(getLocalMillis(), days);
        return withLocalMillis(instant);
    }
    //-----------------------------------------------------------------------
    
Gets the property object for the specified type, which contains many useful methods.

Parameters:
fieldType the field type to get the chronology for
Returns:
the property object
Throws:
IllegalArgumentException if the field is null or unsupported
    public Property property(DateTimeFieldType fieldType) {
        if (fieldType == null) {
            throw new IllegalArgumentException("The DateTimeFieldType must not be null");
        }
        if (isSupported(fieldType) == false) {
            throw new IllegalArgumentException("Field '" + fieldType + "' is not supported");
        }
        return new Property(thisfieldType.getField(getChronology()));
    }
    //-----------------------------------------------------------------------
    
Get the era field value.

Returns:
the era
    public int getEra() {
        return getChronology().era().get(getLocalMillis());
    }

    
Get the year of era field value.

Returns:
the year of era
    public int getCenturyOfEra() {
        return getChronology().centuryOfEra().get(getLocalMillis());
    }

    
Get the year of era field value.

Returns:
the year of era
    public int getYearOfEra() {
        return getChronology().yearOfEra().get(getLocalMillis());
    }

    
Get the year of century field value.

Returns:
the year of century
    public int getYearOfCentury() {
        return getChronology().yearOfCentury().get(getLocalMillis());
    }

    
Get the year field value.

Returns:
the year
    public int getYear() {
        return getChronology().year().get(getLocalMillis());
    }

    
Get the weekyear field value.

The weekyear is the year that matches with the weekOfWeekyear field. In the standard ISO8601 week algorithm, the first week of the year is that in which at least 4 days are in the year. As a result of this definition, day 1 of the first week may be in the previous year. The weekyear allows you to query the effective year for that day.

Returns:
the weekyear
    public int getWeekyear() {
        return getChronology().weekyear().get(getLocalMillis());
    }

    
Get the month of year field value.

Returns:
the month of year
    public int getMonthOfYear() {
        return getChronology().monthOfYear().get(getLocalMillis());
    }

    
Get the week of weekyear field value.

This field is associated with the "weekyear" via getWeekyear(). In the standard ISO8601 week algorithm, the first week of the year is that in which at least 4 days are in the year. As a result of this definition, day 1 of the first week may be in the previous year.

Returns:
the week of a week based year
    public int getWeekOfWeekyear() {
        return getChronology().weekOfWeekyear().get(getLocalMillis());
    }

    
Get the day of year field value.

Returns:
the day of year
    public int getDayOfYear() {
        return getChronology().dayOfYear().get(getLocalMillis());
    }

    
Get the day of month field value.

The values for the day of month are defined in org.joda.time.DateTimeConstants.

Returns:
the day of month
    public int getDayOfMonth() {
        return getChronology().dayOfMonth().get(getLocalMillis());
    }

    
Get the day of week field value.

The values for the day of week are defined in org.joda.time.DateTimeConstants.

Returns:
the day of week
    public int getDayOfWeek() {
        return getChronology().dayOfWeek().get(getLocalMillis());
    }
    //-----------------------------------------------------------------------
    
Returns a copy of this date with the era field updated.

LocalDate is immutable, so there are no set methods. Instead, this method returns a new instance with the value of era changed.

Parameters:
era the era to set
Returns:
a copy of this object with the field set
Throws:
IllegalArgumentException if the value is invalid
    public LocalDate withEra(int era) {
        return withLocalMillis(getChronology().era().set(getLocalMillis(), era));
    }

    
Returns a copy of this date with the century of era field updated.

LocalDate is immutable, so there are no set methods. Instead, this method returns a new instance with the value of century of era changed.

Parameters:
centuryOfEra the centurey of era to set
Returns:
a copy of this object with the field set
Throws:
IllegalArgumentException if the value is invalid
    public LocalDate withCenturyOfEra(int centuryOfEra) {
        return withLocalMillis(getChronology().centuryOfEra().set(getLocalMillis(), centuryOfEra));
    }

    
Returns a copy of this date with the year of era field updated.

LocalDate is immutable, so there are no set methods. Instead, this method returns a new instance with the value of year of era changed.

Parameters:
yearOfEra the year of era to set
Returns:
a copy of this object with the field set
Throws:
IllegalArgumentException if the value is invalid
    public LocalDate withYearOfEra(int yearOfEra) {
        return withLocalMillis(getChronology().yearOfEra().set(getLocalMillis(), yearOfEra));
    }

    
Returns a copy of this date with the year of century field updated.

LocalDate is immutable, so there are no set methods. Instead, this method returns a new instance with the value of year of century changed.

Parameters:
yearOfCentury the year of century to set
Returns:
a copy of this object with the field set
Throws:
IllegalArgumentException if the value is invalid
    public LocalDate withYearOfCentury(int yearOfCentury) {
        return withLocalMillis(getChronology().yearOfCentury().set(getLocalMillis(), yearOfCentury));
    }

    
Returns a copy of this date with the year field updated.

LocalDate is immutable, so there are no set methods. Instead, this method returns a new instance with the value of year changed.

Parameters:
year the year to set
Returns:
a copy of this object with the field set
Throws:
IllegalArgumentException if the value is invalid
    public LocalDate withYear(int year) {
        return withLocalMillis(getChronology().year().set(getLocalMillis(), year));
    }

    
Returns a copy of this date with the weekyear field updated.

The weekyear is the year that matches with the weekOfWeekyear field. In the standard ISO8601 week algorithm, the first week of the year is that in which at least 4 days are in the year. As a result of this definition, day 1 of the first week may be in the previous year. The weekyear allows you to query the effective year for that day.

LocalDate is immutable, so there are no set methods. Instead, this method returns a new instance with the value of weekyear changed.

Parameters:
weekyear the weekyear to set
Returns:
a copy of this object with the field set
Throws:
IllegalArgumentException if the value is invalid
    public LocalDate withWeekyear(int weekyear) {
        return withLocalMillis(getChronology().weekyear().set(getLocalMillis(), weekyear));
    }

    
Returns a copy of this date with the month of year field updated.

LocalDate is immutable, so there are no set methods. Instead, this method returns a new instance with the value of month of year changed.

Parameters:
monthOfYear the month of year to set
Returns:
a copy of this object with the field set
Throws:
IllegalArgumentException if the value is invalid
    public LocalDate withMonthOfYear(int monthOfYear) {
        return withLocalMillis(getChronology().monthOfYear().set(getLocalMillis(), monthOfYear));
    }

    
Returns a copy of this date with the week of weekyear field updated.

This field is associated with the "weekyear" via withWeekyear(int). In the standard ISO8601 week algorithm, the first week of the year is that in which at least 4 days are in the year. As a result of this definition, day 1 of the first week may be in the previous year.

LocalDate is immutable, so there are no set methods. Instead, this method returns a new instance with the value of week of weekyear changed.

Parameters:
weekOfWeekyear the week of weekyear to set
Returns:
a copy of this object with the field set
Throws:
IllegalArgumentException if the value is invalid
    public LocalDate withWeekOfWeekyear(int weekOfWeekyear) {
        return withLocalMillis(getChronology().weekOfWeekyear().set(getLocalMillis(), weekOfWeekyear));
    }

    
Returns a copy of this date with the day of year field updated.

LocalDate is immutable, so there are no set methods. Instead, this method returns a new instance with the value of day of year changed.

Parameters:
dayOfYear the day of year to set
Returns:
a copy of this object with the field set
Throws:
IllegalArgumentException if the value is invalid
    public LocalDate withDayOfYear(int dayOfYear) {
        return withLocalMillis(getChronology().dayOfYear().set(getLocalMillis(), dayOfYear));
    }

    
Returns a copy of this date with the day of month field updated.

LocalDate is immutable, so there are no set methods. Instead, this method returns a new instance with the value of day of month changed.

Parameters:
dayOfMonth the day of month to set
Returns:
a copy of this object with the field set
Throws:
IllegalArgumentException if the value is invalid
    public LocalDate withDayOfMonth(int dayOfMonth) {
        return withLocalMillis(getChronology().dayOfMonth().set(getLocalMillis(), dayOfMonth));
    }

    
Returns a copy of this date with the day of week field updated.

LocalDate is immutable, so there are no set methods. Instead, this method returns a new instance with the value of day of week changed.

Parameters:
dayOfWeek the day of week to set
Returns:
a copy of this object with the field set
Throws:
IllegalArgumentException if the value is invalid
    public LocalDate withDayOfWeek(int dayOfWeek) {
        return withLocalMillis(getChronology().dayOfWeek().set(getLocalMillis(), dayOfWeek));
    }
    //-----------------------------------------------------------------------
    
Get the era property which provides access to advanced functionality.

Returns:
the era property
    public Property era() {
        return new Property(thisgetChronology().era());
    }

    
Get the century of era property which provides access to advanced functionality.

Returns:
the year of era property
    public Property centuryOfEra() {
        return new Property(thisgetChronology().centuryOfEra());
    }

    
Get the year of century property which provides access to advanced functionality.

Returns:
the year of era property
    public Property yearOfCentury() {
        return new Property(thisgetChronology().yearOfCentury());
    }

    
Get the year of era property which provides access to advanced functionality.

Returns:
the year of era property
    public Property yearOfEra() {
        return new Property(thisgetChronology().yearOfEra());
    }

    
Get the year property which provides access to advanced functionality.

Returns:
the year property
    public Property year() {
        return new Property(thisgetChronology().year());
    }

    
Get the weekyear property which provides access to advanced functionality.

Returns:
the weekyear property
    public Property weekyear() {
        return new Property(thisgetChronology().weekyear());
    }

    
Get the month of year property which provides access to advanced functionality.

Returns:
the month of year property
    public Property monthOfYear() {
        return new Property(thisgetChronology().monthOfYear());
    }

    
Get the week of a week based year property which provides access to advanced functionality.

Returns:
the week of a week based year property
    public Property weekOfWeekyear() {
        return new Property(thisgetChronology().weekOfWeekyear());
    }

    
Get the day of year property which provides access to advanced functionality.

Returns:
the day of year property
    public Property dayOfYear() {
        return new Property(thisgetChronology().dayOfYear());
    }

    
Get the day of month property which provides access to advanced functionality.

Returns:
the day of month property
    public Property dayOfMonth() {
        return new Property(thisgetChronology().dayOfMonth());
    }

    
Get the day of week property which provides access to advanced functionality.

Returns:
the day of week property
    public Property dayOfWeek() {
        return new Property(thisgetChronology().dayOfWeek());
    }
    //-----------------------------------------------------------------------
    
Output the date time in ISO8601 format (yyyy-MM-dd).

Returns:
ISO8601 time formatted string.
    @ToString
    public String toString() {
        return ISODateTimeFormat.date().print(this);
    }

    
Output the date using the specified format pattern.

Parameters:
pattern the pattern specification, null means use toString
See also:
org.joda.time.format.DateTimeFormat
    public String toString(String pattern) {
        if (pattern == null) {
            return toString();
        }
        return DateTimeFormat.forPattern(pattern).print(this);
    }

    
Output the date using the specified format pattern.

Parameters:
pattern the pattern specification, null means use toString
locale Locale to use, null means default
See also:
org.joda.time.format.DateTimeFormat
    public String toString(String patternLocale localethrows IllegalArgumentException {
        if (pattern == null) {
            return toString();
        }
        return DateTimeFormat.forPattern(pattern).withLocale(locale).print(this);
    }
    //-----------------------------------------------------------------------
    
LocalDate.Property binds a LocalDate 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).

 LocalDate dt = new LocalDate(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 LocalDate - they do not modify the original. The example below yields two independent immutable date objects 20 years apart.

 LocalDate dt = new LocalDate(1972, 12, 3);
 LocalDate dt1920 = dt.year().setCopy(1920);
 

LocalDate.Property itself is thread-safe and immutable, as well as the LocalDate being operated on.

Author(s):
Stephen Colebourne
Brian S O'Neill
Since:
1.3
    public static final class Property extends AbstractReadableInstantFieldProperty {
        
        
Serialization version
        private static final long serialVersionUID = -3193829732634L;
        
        
The instant this property is working against
        private transient LocalDate iInstant;
        
The field this property is working against
        private transient DateTimeField iField;
        
        
Constructor.

Parameters:
instant the instant to set
field the field to use
        Property(LocalDate instantDateTimeField field) {
            super();
             = instant;
             = field;
        }
        
        
Writes the property in a safe serialization format.
        private void writeObject(ObjectOutputStream oosthrows IOException {
            oos.writeObject();
            oos.writeObject(.getType());
        }

        
Reads the property from a safe serialization format.
        private void readObject(ObjectInputStream oosthrows IOExceptionClassNotFoundException {
             = (LocalDateoos.readObject();
            DateTimeFieldType type = (DateTimeFieldTypeoos.readObject();
             = type.getField(.getChronology());
        }
        //-----------------------------------------------------------------------
        
Gets the field being used.

Returns:
the field
        public DateTimeField getField() {
            return ;
        }
        
        
Gets the milliseconds of the date that this property is linked to.

Returns:
the milliseconds
        protected long getMillis() {
            return .getLocalMillis();
        }
        
        
Gets the chronology of the datetime that this property is linked to.

Returns:
the chronology
Since:
1.4
        protected Chronology getChronology() {
            return .getChronology();
        }
        
        
Gets the LocalDate object linked to this property.

Returns:
the linked LocalDate
        public LocalDate getLocalDate() {
            return ;
        }
        
        //-----------------------------------------------------------------------
        
Adds to this field in a copy of this LocalDate.

The LocalDate 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 LocalDate with the field value changed
Throws:
IllegalArgumentException if the value isn't valid
        public LocalDate addToCopy(int value) {
            return .withLocalMillis(.add(.getLocalMillis(), value));
        }
        
        
Adds to this field, possibly wrapped, in a copy of this LocalDate. A field wrapped operation only changes this field. Thus 31st January addWrapField one day goes to the 1st January.

The LocalDate 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 LocalDate with the field value changed
Throws:
IllegalArgumentException if the value isn't valid
        public LocalDate addWrapFieldToCopy(int value) {
            return .withLocalMillis(.addWrapField(.getLocalMillis(), value));
        }
        
        //-----------------------------------------------------------------------
        
Sets this field in a copy of the LocalDate.

The LocalDate 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 LocalDate with the field value changed
Throws:
IllegalArgumentException if the value isn't valid
        public LocalDate setCopy(int value) {
            return .withLocalMillis(.set(.getLocalMillis(), value));
        }
        
        
Sets this field in a copy of the LocalDate to a parsed text value.

The LocalDate 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 LocalDate with the field value changed
Throws:
IllegalArgumentException if the text value isn't valid
        public LocalDate setCopy(String textLocale locale) {
            return .withLocalMillis(.set(.getLocalMillis(), textlocale));
        }
        
        
Sets this field in a copy of the LocalDate to a parsed text value.

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

Parameters:
text the text value to set
Returns:
a copy of the LocalDate with the field value changed
Throws:
IllegalArgumentException if the text value isn't valid
        public LocalDate setCopy(String text) {
            return setCopy(textnull);
        }
        
        //-----------------------------------------------------------------------
        
Returns a new LocalDate with this field set to the maximum value for this field.

This operation is useful for obtaining a LocalDate on the last day of the month, as month lengths vary.

 LocalDate lastDayOfMonth = dt.dayOfMonth().withMaximumValue();
 

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

Returns:
a copy of the LocalDate with this field set to its maximum
        public LocalDate withMaximumValue() {
            return setCopy(getMaximumValue());
        }
        
        
Returns a new LocalDate with this field set to the minimum value for this field.

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

Returns:
a copy of the LocalDate with this field set to its minimum
        public LocalDate withMinimumValue() {
            return setCopy(getMinimumValue());
        }
        
        //-----------------------------------------------------------------------
        
Rounds to the lowest whole unit of this field on a copy of this LocalDate.

For example, rounding floor on the hourOfDay field of a LocalDate where the time is 10:30 would result in new LocalDate with the time of 10:00.

Returns:
a copy of the LocalDate with the field value changed
        public LocalDate roundFloorCopy() {
        }
        
        
Rounds to the highest whole unit of this field on a copy of this LocalDate.

For example, rounding floor on the hourOfDay field of a LocalDate where the time is 10:30 would result in new LocalDate with the time of 11:00.

Returns:
a copy of the LocalDate with the field value changed
        public LocalDate roundCeilingCopy() {
        }
        
        
Rounds to the nearest whole unit of this field on a copy of this LocalDate, favoring the floor if halfway.

Returns:
a copy of the LocalDate with the field value changed
        public LocalDate roundHalfFloorCopy() {
        }
        
        
Rounds to the nearest whole unit of this field on a copy of this LocalDate, favoring the ceiling if halfway.

Returns:
a copy of the LocalDate with the field value changed
        public LocalDate roundHalfCeilingCopy() {
        }
        
        
Rounds to the nearest whole unit of this field on a copy of this LocalDate. If halfway, the ceiling is favored over the floor only if it makes this field's value even.

Returns:
a copy of the LocalDate with the field value changed
        public LocalDate roundHalfEvenCopy() {
        }
    }