Joda Time API

org.joda.time
Class DateOnly

java.lang.Object
  |
  +--org.joda.time.AbstractInstant
        |
        +--org.joda.time.DateOnly
All Implemented Interfaces:
java.lang.Comparable, ReadableInstant, java.io.Serializable
Direct Known Subclasses:
BuddhistDateOnly, GJDateOnly, ISODateOnly

public class DateOnly
extends AbstractInstant

DateOnly is the basic implementation of a date only class supporting chronologies and time zones. It holds the date as milliseconds from the Java epoch of 1970-01-01T00:00:00Z. There is no time component - the time is always 00:00:00.

Each individual field can be queried in two ways:

The second technique also provides access to other useful methods on the field:

This class is immutable provided that the Chronology is immutable. All Chronology classes supplied are immutable.

Author:
Stephen Colebourne, Brian S O'Neill
See Also:
ISOChronology, ISODateTimeFormat, DateTimeZone.UTC, Serialized Form

Constructor Summary
DateOnly(java.util.Calendar calendar, Chronology chronology)
          Constructs a DateOnly from a Calendar.
DateOnly(Chronology chronology)
          Constructs a DateOnly to the current date, as reported by the system clock.
DateOnly(java.util.Date date, Chronology chronology)
          Constructs a DateOnly from a Date.
DateOnly(long millis, Chronology chronology)
          Constructs a DateOnly set to the milliseconds from 1970-01-01T00:00:00Z.
DateOnly(ReadableInstant instant, Chronology chronology)
          Constructs a DateOnly from a ReadableInstant.
DateOnly(java.lang.String str, Chronology chronology)
          Constructs a DateOnly from an ISO formatted String.
 
Method Summary
 DateTimeFieldProperty dayOfMonth()
          Get the day of month property.
 DateTimeFieldProperty dayOfWeek()
          Get the day of week property.
 DateTimeFieldProperty dayOfYear()
          Get the day of year property.
 DateTimeFieldProperty era()
          Get the era property.
 Chronology getChronology()
          Gets the chronology of the date.
 int getDayOfMonth()
          Get the day of month field value.
 int getDayOfWeek()
          Get the day of week field value.
 int getDayOfYear()
          Get the day of year field value.
 int getEra()
          Get the era field value.
 int getLeapYear()
          Get the leap year field value.
 long getMillis()
          Gets the milliseconds of the date instant from the Java epoch of 1970-01-01T00:00:00Z.
 int getMonthOfYear()
          Get the month of year field value.
 int getWeekOfYearWeek()
          Get the week of year week field value.
 int getWeekOfYearYear()
          Get the week of year year field value.
 int getYear()
          Get the year field value.
 int getYearOfEra()
          Get the year of era field value.
 DateTimeFieldProperty leapYear()
          Get the leap year property.
 DateTimeFieldProperty monthOfYear()
          Get the month of year property.
 java.lang.String toString()
          Output the date time in ISO8601 date only format (YYYY-MM-DD).
 DateTimeFieldProperty weekOfYearWeek()
          Get the week of year week property.
 DateTimeFieldProperty weekOfYearYear()
          Get the week of year year property.
 DateTimeFieldProperty year()
          Get the year property.
 DateTimeFieldProperty yearOfEra()
          Get the year of era property.
 
Methods inherited from class org.joda.time.AbstractInstant
compareTo, equals, get, hashCode, isAfter, isBefore, isEqual, toCalendar, toDate, toGregorianCalendar, toInstant
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DateOnly

public DateOnly(Chronology chronology)
Constructs a DateOnly to the current date, as reported by the system clock. If the supplied chronology is null, it defaults to ISO, in the time zone returned by DateTimeZone.getDefault().

Parameters:
chronology - the chronology, null is ISO

DateOnly

public DateOnly(long millis,
                Chronology chronology)
Constructs a DateOnly set to the milliseconds from 1970-01-01T00:00:00Z. If the supplied chronology is null, it defaults to ISO, in the time zone returned by DateTimeZone.getDefault().

Parameters:
millis - the milliseconds
chronology - the chronology, null is ISO

DateOnly

public DateOnly(ReadableInstant instant,
                Chronology chronology)
Constructs a DateOnly from a ReadableInstant. If the supplied chronology is null, it defaults to the chronology of the supplied instant. If that chronology is also null, then the chronology is set to ISO, in the time zone returned by DateTimeZone.getDefault().

Parameters:
instant - the ReadableInstant, must not be null
chronology - the chronology, null means use instant to determine
Throws:
java.lang.IllegalArgumentException - if the instant is null

DateOnly

public DateOnly(java.util.Date date,
                Chronology chronology)
Constructs a DateOnly from a Date. If the supplied chronology is null, it defaults to ISO, in the time zone returned by DateTimeZone.getDefault().

Parameters:
date - the Date, must not be null
chronology - the chronology, null is ISO
Throws:
java.lang.IllegalArgumentException - if the date is null

DateOnly

public DateOnly(java.util.Calendar calendar,
                Chronology chronology)
Constructs a DateOnly from a Calendar.

If the chronology is specified, it is used. If null, the chronology and time zone from the calendar is used. If that cannot be determined, ISOChronology in the default time zone is used.

When converting calendars to chronologies, the constructor is aware of GregorianCalendar and BuddhistCalendar and maps them to the equivalent chronology. Other calendars map to ISOChronology.

Parameters:
calendar - the Calendar, must not be null
chronology - the chronology, null means use calendar to determine
Throws:
java.lang.IllegalArgumentException - if the calendar is null

DateOnly

public DateOnly(java.lang.String str,
                Chronology chronology)
         throws java.text.ParseException
Constructs a DateOnly from an ISO formatted String. If the supplied chronology is null, it defaults to ISO, in the time zone returned by DateTimeZone.getDefault().

Parameters:
str - the string to parse, must not be null
chronology - the chronology, null is ISO
Throws:
java.lang.IllegalArgumentException - if the string is null
java.text.ParseException - if parsing fails
Method Detail

getMillis

public final long getMillis()
Gets the milliseconds of the date instant from the Java epoch of 1970-01-01T00:00:00Z.

Returns:
the number of milliseconds since 1970-01-01T00:00:00Z

getChronology

public final Chronology getChronology()
Gets the chronology of the date.

Returns:
the Chronology that the date is using

getDayOfWeek

public final int getDayOfWeek()
Get the day of week field value.

Returns:
the day of week

getDayOfMonth

public final int getDayOfMonth()
Get the day of month field value.

Returns:
the day of month

getDayOfYear

public final int getDayOfYear()
Get the day of year field value.

Returns:
the day of year

getWeekOfYearWeek

public final int getWeekOfYearWeek()
Get the week of year week field value.

Returns:
the week of year week

getWeekOfYearYear

public final int getWeekOfYearYear()
Get the week of year year field value.

Returns:
the week of year year

getMonthOfYear

public final int getMonthOfYear()
Get the month of year field value.

Returns:
the month of year

getYear

public final int getYear()
Get the year field value.

Returns:
the year

getYearOfEra

public final int getYearOfEra()
Get the year of era field value.

Returns:
the year of era

getEra

public final int getEra()
Get the era field value.

Returns:
the era

getLeapYear

public final int getLeapYear()
Get the leap year field value.

Returns:
the leap year constant as specified in DateTimeConstants

dayOfWeek

public final DateTimeFieldProperty dayOfWeek()
Get the day of week property.

Returns:
the day of week property

dayOfMonth

public final DateTimeFieldProperty dayOfMonth()
Get the day of month property.

Returns:
the day of month property

dayOfYear

public final DateTimeFieldProperty dayOfYear()
Get the day of year property.

Returns:
the day of year property

weekOfYearWeek

public final DateTimeFieldProperty weekOfYearWeek()
Get the week of year week property.

Returns:
the week of year week property

weekOfYearYear

public final DateTimeFieldProperty weekOfYearYear()
Get the week of year year property.

Returns:
the week of year year property

monthOfYear

public final DateTimeFieldProperty monthOfYear()
Get the month of year property.

Returns:
the month of year property

year

public final DateTimeFieldProperty year()
Get the year property.

Returns:
the year property

yearOfEra

public final DateTimeFieldProperty yearOfEra()
Get the year of era property.

Returns:
the year of era property

era

public final DateTimeFieldProperty era()
Get the era property.

Returns:
the era property

leapYear

public final DateTimeFieldProperty leapYear()
Get the leap year property.

Returns:
the leap year property

toString

public final java.lang.String toString()
Output the date time in ISO8601 date only format (YYYY-MM-DD).

Specified by:
toString in interface ReadableInstant
Overrides:
toString in class java.lang.Object
Returns:
ISO8601 date formatted string

Joda Time API

Copyright © 2001-2003 Stephen Colebourne. All Rights Reserved.