public abstract class

AbstractDateTime

extends AbstractInstant
implements ReadableDateTime
java.lang.Object
   ↳ org.joda.time.base.AbstractInstant
     ↳ org.joda.time.base.AbstractDateTime
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

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.

Summary

Protected Constructors
AbstractDateTime()
Constructor.
Public Methods
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, Locale locale)
Output the instant using the specified format pattern.
String toString(String pattern)
Output the instant using the specified format pattern.
[Expand]
Inherited Methods
From class org.joda.time.base.AbstractInstant
From class java.lang.Object
From interface java.lang.Comparable
From interface org.joda.time.ReadableDateTime
From interface org.joda.time.ReadableInstant

Protected Constructors

protected AbstractDateTime ()

Constructor.

Public Methods

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.

Parameters
type a field type, usually obtained from DateTimeFieldType
Returns
  • the value of that field
Throws
IllegalArgumentException if the field type is null

public int getCenturyOfEra ()

Get the year of era field value.

Returns
  • the year of era

public int getDayOfMonth ()

Get the day of month field value.

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

Returns
  • the day of month

public int getDayOfWeek ()

Get the day of week field value.

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

Returns
  • the day of week

public int getDayOfYear ()

Get the day of year field value.

Returns
  • the day of year

public int getEra ()

Get the era field value.

Returns
  • the era

public int getHourOfDay ()

Get the hour of day field value.

Returns
  • the hour of day

public int getMillisOfDay ()

Get the millis of day field value.

Returns
  • the millis of day

public int getMillisOfSecond ()

Get the millis of second field value.

Returns
  • the millis of second

public int getMinuteOfDay ()

Get the minute of day field value.

Returns
  • the minute of day

public int getMinuteOfHour ()

Get the minute of hour field value.

Returns
  • the minute of hour

public int getMonthOfYear ()

Get the month of year field value.

Returns
  • the month of year

public int getSecondOfDay ()

Get the second of day field value.

Returns
  • the second of day

public int getSecondOfMinute ()

Get the second of minute field value.

Returns
  • the second of minute

public int getWeekOfWeekyear ()

Get the week of weekyear field value.

Returns
  • the week of a week based year

public int getWeekyear ()

Get the weekyear field value.

Returns
  • the year of a week based year

public int getYear ()

Get the year field value.

Returns
  • the year

public int getYearOfCentury ()

Get the year of century field value.

Returns
  • the year of century

public int getYearOfEra ()

Get the year of era field value.

Returns
  • the year of era

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

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

public String toString (String pattern, Locale locale)

Output the instant using the specified format pattern.

Parameters
pattern the pattern specification, null means use toString
locale Locale to use, null means default
See Also

public String toString (String pattern)

Output the instant using the specified format pattern.

Parameters
pattern the pattern specification, null means use toString
See Also