org.joda.time.base

Class AbstractDateTime

Implemented Interfaces:
Comparable, ReadableDateTime, ReadableInstant
Known Direct 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.

Authors:
Brian S O'Neill
Stephen Colebourne
Since:
1.0

Constructor Summary

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, 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

Constructor Details

AbstractDateTime

protected AbstractDateTime()
Constructor.

Method Details

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 interface AbstractInstant
Parameters:
type - a field type, usually obtained from DateTimeFieldType
Returns:
the value of that field

getCenturyOfEra

public int getCenturyOfEra()
Get the year of era field value.
Specified by:
getCenturyOfEra in interface ReadableDateTime
Returns:
the year of era

getDayOfMonth

public int getDayOfMonth()
Specified by:
getDayOfMonth in interface ReadableDateTime
Returns:
the day of month

getDayOfWeek

public int getDayOfWeek()
Specified by:
getDayOfWeek in interface ReadableDateTime
Returns:
the day of week

getDayOfYear

public int getDayOfYear()
Get the day of year field value.
Specified by:
getDayOfYear in interface ReadableDateTime
Returns:
the day of year

getEra

public int getEra()
Get the era field value.
Specified by:
getEra in interface ReadableDateTime
Returns:
the era

getHourOfDay

public int getHourOfDay()
Get the hour of day field value.
Specified by:
getHourOfDay in interface ReadableDateTime
Returns:
the hour of day

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

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

getMonthOfYear

public int getMonthOfYear()
Get the month of year field value.
Specified by:
getMonthOfYear in interface ReadableDateTime
Returns:
the month of year

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

getWeekOfWeekyear

public int getWeekOfWeekyear()
Get the week of weekyear field value.
Specified by:
getWeekOfWeekyear in interface ReadableDateTime
Returns:
the week of a week based year

getWeekyear

public int getWeekyear()
Get the weekyear field value.
Specified by:
getWeekyear in interface ReadableDateTime
Returns:
the year of a week based year

getYear

public int getYear()
Get the year field value.
Specified by:
getYear in interface ReadableDateTime
Returns:
the year

getYearOfCentury

public int getYearOfCentury()
Get the year of century field value.
Specified by:
getYearOfCentury in interface ReadableDateTime
Returns:
the year of century

getYearOfEra

public int getYearOfEra()
Get the year of era field value.
Specified by:
getYearOfEra in interface ReadableDateTime
Returns:
the year of era

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

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

Copyright (c) 2001-2006 - Joda.org