org.joda.time.base
Class AbstractDateTime

java.lang.Object
  extended by org.joda.time.base.AbstractInstant
      extended by org.joda.time.base.AbstractDateTime
All Implemented Interfaces:
Comparable<ReadableInstant>, ReadableDateTime, ReadableInstant
Direct Known Subclasses:
BaseDateTime

public abstract class AbstractDateTime
extends AbstractInstant
implements ReadableDateTime

AbstractDateTime provides the common behaviour for datetime classes.

This class should generally not be used directly by API users. The ReadableDateTime interface should be used when different kinds of date/time objects are to be referenced.

Whenever you want to implement ReadableDateTime you should extend this class.

AbstractDateTime subclasses may be mutable and not thread-safe.

Since:
1.0
Author:
Brian S O'Neill, Stephen Colebourne

Constructor Summary
protected AbstractDateTime()
          Constructor.
 
Method Summary
 int get(DateTimeFieldType type)
          Get the value of one of the fields of a datetime.
 int getCenturyOfEra()
          Get the year of era field value.
 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 getHourOfDay()
          Get the hour of day field value.
 int getMillisOfDay()
          Get the millis of day field value.
 int getMillisOfSecond()
          Get the millis of second field value.
 int getMinuteOfDay()
          Get the minute of day field value.
 int getMinuteOfHour()
          Get the minute of hour field value.
 int getMonthOfYear()
          Get the month of year field value.
 int getSecondOfDay()
          Get the second of day field value.
 int getSecondOfMinute()
          Get the second of minute field value.
 int getWeekOfWeekyear()
          Get the week of weekyear field value.
 int getWeekyear()
          Get the weekyear field value.
 int getYear()
          Get the year field value.
 int getYearOfCentury()
          Get the year of century field value.
 int getYearOfEra()
          Get the year of era field value.
 Calendar toCalendar(Locale locale)
          Get the date time as a java.util.Calendar, assigning exactly the same millisecond instant.
 GregorianCalendar toGregorianCalendar()
          Get the date time as a java.util.GregorianCalendar, assigning exactly the same millisecond instant.
 String toString(String pattern)
          Output the instant using the specified format pattern.
 String toString(String pattern, Locale locale)
          Output the instant using the specified format pattern.
 
Methods inherited from class org.joda.time.base.AbstractInstant
compareTo, equals, get, getZone, hashCode, isAfter, isAfter, isAfterNow, isBefore, isBefore, isBeforeNow, isEqual, isEqual, isEqualNow, isSupported, toDate, toDateTime, toDateTime, toDateTime, toDateTimeISO, toInstant, toMutableDateTime, toMutableDateTime, toMutableDateTime, toMutableDateTimeISO, toString, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.joda.time.ReadableDateTime
toDateTime, toMutableDateTime
 
Methods inherited from interface org.joda.time.ReadableInstant
equals, getChronology, getMillis, getZone, hashCode, isAfter, isBefore, isEqual, isSupported, toInstant, toString
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Constructor Detail

AbstractDateTime

protected AbstractDateTime()
Constructor.

Method Detail

get

public int get(DateTimeFieldType type)
Get the value of one of the fields of a datetime.

This method uses the chronology of the datetime to obtain the value. It is essentially a generic way of calling one of the get methods.

Specified by:
get in interface ReadableInstant
Overrides:
get in class AbstractInstant
Parameters:
type - a field type, usually obtained from DateTimeFieldType
Returns:
the value of that field
Throws:
IllegalArgumentException - if the field type is null

getEra

public int getEra()
Get the era field value.

Specified by:
getEra in interface ReadableDateTime
Returns:
the era

getCenturyOfEra

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

Specified by:
getCenturyOfEra in interface ReadableDateTime
Returns:
the year of era

getYearOfEra

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

Specified by:
getYearOfEra in interface ReadableDateTime
Returns:
the year of era

getYearOfCentury

public int getYearOfCentury()
Get the year of century field value.

Specified by:
getYearOfCentury in interface ReadableDateTime
Returns:
the year of century

getYear

public int getYear()
Get the year field value.

Specified by:
getYear in interface ReadableDateTime
Returns:
the year

getWeekyear

public int getWeekyear()
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.

Specified by:
getWeekyear in interface ReadableDateTime
Returns:
the year of a week based year

getMonthOfYear

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

Specified by:
getMonthOfYear in interface ReadableDateTime
Returns:
the month of year

getWeekOfWeekyear

public int getWeekOfWeekyear()
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.

Specified by:
getWeekOfWeekyear in interface ReadableDateTime
Returns:
the week of a week based year

getDayOfYear

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

Specified by:
getDayOfYear in interface ReadableDateTime
Returns:
the day of year

getDayOfMonth

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

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

Specified by:
getDayOfMonth in interface ReadableDateTime
Returns:
the day of month

getDayOfWeek

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

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

Specified by:
getDayOfWeek in interface ReadableDateTime
Returns:
the day of week

getHourOfDay

public int getHourOfDay()
Get the hour of day field value.

Specified by:
getHourOfDay in interface ReadableDateTime
Returns:
the hour of day

getMinuteOfDay

public int getMinuteOfDay()
Get the minute of day field value.

Specified by:
getMinuteOfDay in interface ReadableDateTime
Returns:
the minute of day

getMinuteOfHour

public int getMinuteOfHour()
Get the minute of hour field value.

Specified by:
getMinuteOfHour in interface ReadableDateTime
Returns:
the minute of hour

getSecondOfDay

public int getSecondOfDay()
Get the second of day field value.

Specified by:
getSecondOfDay in interface ReadableDateTime
Returns:
the second of day

getSecondOfMinute

public int getSecondOfMinute()
Get the second of minute field value.

Specified by:
getSecondOfMinute in interface ReadableDateTime
Returns:
the second of minute

getMillisOfDay

public int getMillisOfDay()
Get the millis of day field value.

Specified by:
getMillisOfDay in interface ReadableDateTime
Returns:
the millis of day

getMillisOfSecond

public int getMillisOfSecond()
Get the millis of second field value.

Specified by:
getMillisOfSecond in interface ReadableDateTime
Returns:
the millis of second

toCalendar

public Calendar toCalendar(Locale locale)
Get the date time as a java.util.Calendar, assigning exactly the same millisecond instant. The locale is passed in, enabling Calendar to select the correct localized subclass.

The JDK and Joda-Time both have time zone implementations and these differ in accuracy. Joda-Time's implementation is generally more up to date and thus more accurate - for example JDK1.3 has no historical data. The effect of this is that the field values of the Calendar may differ from those of this object, even though the milliseond value is the same. Most of the time this just means that the JDK field values are wrong, as our time zone information is more up to date.

Parameters:
locale - the locale to get the Calendar for, or default if null
Returns:
a localized Calendar initialised with this datetime

toGregorianCalendar

public GregorianCalendar toGregorianCalendar()
Get the date time as a java.util.GregorianCalendar, assigning exactly the same millisecond instant.

The JDK and Joda-Time both have time zone implementations and these differ in accuracy. Joda-Time's implementation is generally more up to date and thus more accurate - for example JDK1.3 has no historical data. The effect of this is that the field values of the Calendar may differ from those of this object, even though the milliseond value is the same. Most of the time this just means that the JDK field values are wrong, as our time zone information is more up to date.

Returns:
a GregorianCalendar initialised with this datetime

toString

public String toString(String pattern)
Output the instant using the specified format pattern.

Specified by:
toString in interface ReadableDateTime
Parameters:
pattern - the pattern specification, null means use toString
See Also:
DateTimeFormat

toString

public String toString(String pattern,
                       Locale locale)
                throws IllegalArgumentException
Output the instant using the specified format pattern.

Specified by:
toString in interface ReadableDateTime
Parameters:
pattern - the pattern specification, null means use toString
locale - Locale to use, null means default
Throws:
IllegalArgumentException - if pattern is invalid
See Also:
DateTimeFormat


Copyright © 2002-2013 Joda.org. All Rights Reserved.