Class AbstractDateTime
- java.lang.Object
-
- org.joda.time.base.AbstractInstant
-
- org.joda.time.base.AbstractDateTime
-
- All Implemented Interfaces:
java.lang.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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.java.util.Calendar
toCalendar(java.util.Locale locale)
Get the date time as ajava.util.Calendar
, assigning exactly the same millisecond instant.java.util.GregorianCalendar
toGregorianCalendar()
Get the date time as ajava.util.GregorianCalendar
, assigning exactly the same millisecond instant.java.lang.String
toString()
Output the date time in ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSSZZ).java.lang.String
toString(java.lang.String pattern)
Output the instant using the specified format pattern.java.lang.String
toString(java.lang.String pattern, java.util.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
-
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
-
-
-
-
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 interfaceReadableInstant
- Overrides:
get
in classAbstractInstant
- Parameters:
type
- a field type, usually obtained from DateTimeFieldType- Returns:
- the value of that field
- Throws:
java.lang.IllegalArgumentException
- if the field type is null
-
getEra
public int getEra()
Get the era field value.- Specified by:
getEra
in interfaceReadableDateTime
- Returns:
- the era
-
getCenturyOfEra
public int getCenturyOfEra()
Get the year of era field value.- Specified by:
getCenturyOfEra
in interfaceReadableDateTime
- Returns:
- the year of era
-
getYearOfEra
public int getYearOfEra()
Get the year of era field value.- Specified by:
getYearOfEra
in interfaceReadableDateTime
- Returns:
- the year of era
-
getYearOfCentury
public int getYearOfCentury()
Get the year of century field value.- Specified by:
getYearOfCentury
in interfaceReadableDateTime
- Returns:
- the year of century
-
getYear
public int getYear()
Get the year field value.- Specified by:
getYear
in interfaceReadableDateTime
- 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 interfaceReadableDateTime
- Returns:
- the year of a week based year
-
getMonthOfYear
public int getMonthOfYear()
Get the month of year field value.- Specified by:
getMonthOfYear
in interfaceReadableDateTime
- 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 interfaceReadableDateTime
- Returns:
- the week of a week based year
-
getDayOfYear
public int getDayOfYear()
Get the day of year field value.- Specified by:
getDayOfYear
in interfaceReadableDateTime
- 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 interfaceReadableDateTime
- 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 interfaceReadableDateTime
- Returns:
- the day of week
-
getHourOfDay
public int getHourOfDay()
Get the hour of day field value.- Specified by:
getHourOfDay
in interfaceReadableDateTime
- Returns:
- the hour of day
-
getMinuteOfDay
public int getMinuteOfDay()
Get the minute of day field value.- Specified by:
getMinuteOfDay
in interfaceReadableDateTime
- Returns:
- the minute of day
-
getMinuteOfHour
public int getMinuteOfHour()
Get the minute of hour field value.- Specified by:
getMinuteOfHour
in interfaceReadableDateTime
- Returns:
- the minute of hour
-
getSecondOfDay
public int getSecondOfDay()
Get the second of day field value.- Specified by:
getSecondOfDay
in interfaceReadableDateTime
- Returns:
- the second of day
-
getSecondOfMinute
public int getSecondOfMinute()
Get the second of minute field value.- Specified by:
getSecondOfMinute
in interfaceReadableDateTime
- Returns:
- the second of minute
-
getMillisOfDay
public int getMillisOfDay()
Get the millis of day field value.- Specified by:
getMillisOfDay
in interfaceReadableDateTime
- Returns:
- the millis of day
-
getMillisOfSecond
public int getMillisOfSecond()
Get the millis of second field value.- Specified by:
getMillisOfSecond
in interfaceReadableDateTime
- Returns:
- the millis of second
-
toCalendar
public java.util.Calendar toCalendar(java.util.Locale locale)
Get the date time as ajava.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 millisecond 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 java.util.GregorianCalendar toGregorianCalendar()
Get the date time as ajava.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 millisecond 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 java.lang.String toString()
Output the date time in ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSSZZ).Note that this method does not output the chronology or time-zone. This can be confusing, as the equals and hashCode methods use both chronology and time-zone. If two objects are not
equal
but have the sametoString
then either the chronology or time-zone differs.- Specified by:
toString
in interfaceReadableInstant
- Overrides:
toString
in classAbstractInstant
- Returns:
- ISO8601 time formatted string, not null
-
toString
public java.lang.String toString(java.lang.String pattern)
Output the instant using the specified format pattern.- Specified by:
toString
in interfaceReadableDateTime
- Parameters:
pattern
- the pattern specification, null means usetoString
- Returns:
- the formatted string, not null
- See Also:
DateTimeFormat
-
toString
public java.lang.String toString(java.lang.String pattern, java.util.Locale locale) throws java.lang.IllegalArgumentException
Output the instant using the specified format pattern.- Specified by:
toString
in interfaceReadableDateTime
- Parameters:
pattern
- the pattern specification, null means usetoString
locale
- Locale to use, null means default- Returns:
- the formatted string, not null
- Throws:
java.lang.IllegalArgumentException
- if pattern is invalid- See Also:
DateTimeFormat
-
-