org.joda.time
Class DateTime

java.lang.Object
  extended byorg.joda.time.base.AbstractInstant
      extended byorg.joda.time.base.AbstractDateTime
          extended byorg.joda.time.base.BaseDateTime
              extended byorg.joda.time.DateTime
All Implemented Interfaces:
Comparable, ReadableDateTime, ReadableInstant, Serializable

public final class DateTime
extends BaseDateTime
implements ReadableDateTime, Serializable

DateTime is the standard implementation of an unmodifiable datetime class. It holds the datetime as milliseconds from the Java epoch of 1970-01-01T00:00:00Z.

This class uses a Chronology internally. The Chronology determines how the millisecond instant value is converted into the date time fields. The default Chronology is ISOChronology which is the agreed international standard and compatable with the modern Gregorian calendar.

Each individual field can be queried in two ways:

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

DateTime is thread-safe and immutable, provided that the Chronology is as well. All standard Chronology classes supplied are thread-safe and immutable.

Since:
1.0
Author:
Stephen Colebourne, Kandarp Shah, Brian S O'Neill
See Also:
MutableDateTime, Serialized Form

Nested Class Summary
static class DateTime.Property
          DateTime.Property binds a DateTime to a DateTimeField allowing powerful datetime functionality to be easily accessed.
 
Constructor Summary
DateTime()
          Constructs an instance set to the current system millisecond time using ISOChronology in the default time zone.
DateTime(Chronology chronology)
          Constructs an instance set to the current system millisecond time using the specified chronology.
DateTime(DateTimeZone zone)
          Constructs an instance set to the current system millisecond time using ISOChronology in the specified time zone.
DateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)
          Constructs an instance from datetime field values using ISOChronology in the default time zone.
DateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond, Chronology chronology)
          Constructs an instance from datetime field values using the specified chronology.
DateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond, DateTimeZone zone)
          Constructs an instance from datetime field values using ISOChronology in the specified time zone.
DateTime(long instant)
          Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z using ISOChronology in the default time zone.
DateTime(long instant, Chronology chronology)
          Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z using the specified chronology.
DateTime(long instant, DateTimeZone zone)
          Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z using ISOChronology in the specified time zone.
DateTime(Object instant)
          Constructs an instance from an Object that represents a datetime.
DateTime(Object instant, Chronology chronology)
          Constructs an instance from an Object that represents a datetime, using the specified chronology.
DateTime(Object instant, DateTimeZone zone)
          Constructs an instance from an Object that represents a datetime, forcing the time zone to that specified.
 
Method Summary
 DateTime.Property centuryOfEra()
          Get the century of era property.
 DateTime.Property dayOfMonth()
          Get the day of month property.
 DateTime.Property dayOfWeek()
          Get the day of week property.
 DateTime.Property dayOfYear()
          Get the day of year property.
 DateTime.Property era()
          Get the era property.
 DateTime.Property hourOfDay()
          Get the hour of day field property
 DateTime.Property millisOfDay()
          Get the millis of day property
 DateTime.Property millisOfSecond()
          Get the millis of second property
 DateTime minus(long duration)
          Gets a copy of this datetime with the specified duration take away.
 DateTime minus(ReadableDuration duration)
          Gets a copy of this datetime with the specified duration take away.
 DateTime minus(ReadablePeriod period)
          Gets a copy of this datetime with the specified period take away.
 DateTime minusDays(int days)
          Returns a new datetime minus the specified number of days.
 DateTime minusHours(int hours)
          Returns a new datetime minus the specified number of hours.
 DateTime minusMillis(int millis)
          Returns a new datetime minus the specified number of millis.
 DateTime minusMinutes(int minutes)
          Returns a new datetime minus the specified number of minutes.
 DateTime minusMonths(int months)
          Returns a new datetime minus the specified number of months.
 DateTime minusSeconds(int seconds)
          Returns a new datetime minus the specified number of seconds.
 DateTime minusWeeks(int weeks)
          Returns a new datetime minus the specified number of weeks.
 DateTime minusYears(int years)
          Returns a new datetime minus the specified number of years.
 DateTime.Property minuteOfDay()
          Get the minute of day property
 DateTime.Property minuteOfHour()
          Get the minute of hour field property
 DateTime.Property monthOfYear()
          Get the month of year property.
 DateTime plus(long duration)
          Gets a copy of this datetime with the specified duration added.
 DateTime plus(ReadableDuration duration)
          Gets a copy of this datetime with the specified duration added.
 DateTime plus(ReadablePeriod period)
          Gets a copy of this datetime with the specified period added.
 DateTime plusDays(int days)
          Returns a new datetime plus the specified number of days.
 DateTime plusHours(int hours)
          Returns a new datetime plus the specified number of hours.
 DateTime plusMillis(int millis)
          Returns a new datetime plus the specified number of millis.
 DateTime plusMinutes(int minutes)
          Returns a new datetime plus the specified number of minutes.
 DateTime plusMonths(int months)
          Returns a new datetime plus the specified number of months.
 DateTime plusSeconds(int seconds)
          Returns a new datetime plus the specified number of seconds.
 DateTime plusWeeks(int weeks)
          Returns a new datetime plus the specified number of weeks.
 DateTime plusYears(int years)
          Returns a new datetime plus the specified number of years.
 DateTime.Property property(DateTimeFieldType type)
          Gets the property object for the specified type, which contains many useful methods.
 DateTime.Property secondOfDay()
          Get the second of day property
 DateTime.Property secondOfMinute()
          Get the second of minute field property
 DateMidnight toDateMidnight()
          Converts this object to a DateMidnight using the same millis and chronology.
 DateTime toDateTime()
          Get this object as a DateTime by returning this.
 DateTime toDateTime(Chronology chronology)
          Get this object as a DateTime, returning this if possible.
 DateTime toDateTime(DateTimeZone zone)
          Get this object as a DateTime, returning this if possible.
 DateTime toDateTimeISO()
          Get this object as a DateTime using ISOChronology in the default zone, returning this if possible.
 TimeOfDay toTimeOfDay()
          Converts this object to a TimeOfDay using the same millis and chronology.
 YearMonthDay toYearMonthDay()
          Converts this object to a YearMonthDay using the same millis and chronology.
 DateTime.Property weekOfWeekyear()
          Get the week of a week based year property.
 DateTime.Property weekyear()
          Get the year of a week based year property.
 DateTime withChronology(Chronology newChronology)
          Gets a copy of this datetime with a different chronology.
 DateTime withDate(int year, int monthOfYear, int dayOfMonth)
          Gets a copy of this datetime with the specified date, retaining the time fields.
 DateTime withDurationAdded(long durationToAdd, int scalar)
          Gets a copy of this datetime with the specified duration added.
 DateTime withDurationAdded(ReadableDuration durationToAdd, int scalar)
          Gets a copy of this datetime with the specified duration added.
 DateTime withField(DateTimeFieldType fieldType, int value)
          Gets a copy of this datetime with the specified field set to a new value.
 DateTime withFieldAdded(DurationFieldType fieldType, int amount)
          Gets a copy of this datetime with the value of the specified field increased.
 DateTime withFields(ReadablePartial partial)
          Gets a copy of this datetime with the partial set of fields replacing those from this instance.
 DateTime withMillis(long newMillis)
          Gets a copy of this datetime with different millis.
 DateTime withPeriodAdded(ReadablePeriod period, int scalar)
          Gets a copy of this datetime with the specified period added.
 DateTime withTime(int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)
          Gets a copy of this datetime with the specified time, retaining the date fields.
 DateTime withZone(DateTimeZone newZone)
          Gets a copy of this datetime with a different time zone, preserving the millisecond instant.
 DateTime withZoneRetainFields(DateTimeZone newZone)
          Gets a copy of this datetime with a different time zone, preserving the field values.
 DateTime.Property year()
          Get the year property.
 DateTime.Property yearOfCentury()
          Get the year of century property.
 DateTime.Property yearOfEra()
          Get the year of era property.
 
Methods inherited from class org.joda.time.base.BaseDateTime
getChronology, getMillis
 
Methods inherited from class org.joda.time.base.AbstractDateTime
get, getCenturyOfEra, getDayOfMonth, getDayOfWeek, getDayOfYear, getEra, getHourOfDay, getMillisOfDay, getMillisOfSecond, getMinuteOfDay, getMinuteOfHour, getMonthOfYear, getSecondOfDay, getSecondOfMinute, getWeekOfWeekyear, getWeekyear, getYear, getYearOfCentury, getYearOfEra, toCalendar, toGregorianCalendar, toString, toString
 
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, toInstant, toMutableDateTime, toMutableDateTime, toMutableDateTime, toMutableDateTimeISO, toString, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.joda.time.ReadableDateTime
getCenturyOfEra, getDayOfMonth, getDayOfWeek, getDayOfYear, getEra, getHourOfDay, getMillisOfDay, getMillisOfSecond, getMinuteOfDay, getMinuteOfHour, getMonthOfYear, getSecondOfDay, getSecondOfMinute, getWeekOfWeekyear, getWeekyear, getYear, getYearOfCentury, getYearOfEra, toMutableDateTime, toString, toString
 
Methods inherited from interface org.joda.time.ReadableInstant
compareTo, equals, get, getChronology, getMillis, getZone, hashCode, isAfter, isBefore, isEqual, isSupported, toInstant, toString
 

Constructor Detail

DateTime

public DateTime()
Constructs an instance set to the current system millisecond time using ISOChronology in the default time zone.


DateTime

public DateTime(DateTimeZone zone)
Constructs an instance set to the current system millisecond time using ISOChronology in the specified time zone.

If the specified time zone is null, the default zone is used.

Parameters:
zone - the time zone, null means default zone

DateTime

public DateTime(Chronology chronology)
Constructs an instance set to the current system millisecond time using the specified chronology.

If the chronology is null, ISOChronology in the default time zone is used.

Parameters:
chronology - the chronology, null means ISOChronology in default zone

DateTime

public DateTime(long instant)
Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z using ISOChronology in the default time zone.

Parameters:
instant - the milliseconds from 1970-01-01T00:00:00Z

DateTime

public DateTime(long instant,
                DateTimeZone zone)
Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z using ISOChronology in the specified time zone.

If the specified time zone is null, the default zone is used.

Parameters:
instant - the milliseconds from 1970-01-01T00:00:00Z
zone - the time zone, null means default zone

DateTime

public DateTime(long instant,
                Chronology chronology)
Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z using the specified chronology.

If the chronology is null, ISOChronology in the default time zone is used.

Parameters:
instant - the milliseconds from 1970-01-01T00:00:00Z
chronology - the chronology, null means ISOChronology in default zone

DateTime

public DateTime(Object instant)
Constructs an instance from an Object that represents a datetime.

If the object implies a chronology (such as GregorianCalendar does), then that chronology will be used. Otherwise, ISO default is used. Thus if a GregorianCalendar is passed in, the chronology used will be GJ, but if a Date is passed in the chronology will be ISO.

The recognised object types are defined in ConverterManager and include ReadableInstant, String, Calendar and Date.

Parameters:
instant - the datetime object, null means now
Throws:
IllegalArgumentException - if the instant is invalid

DateTime

public DateTime(Object instant,
                DateTimeZone zone)
Constructs an instance from an Object that represents a datetime, forcing the time zone to that specified.

If the object implies a chronology (such as GregorianCalendar does), then that chronology will be used, but with the time zone adjusted. Otherwise, ISO is used in the specified time zone. If the specified time zone is null, the default zone is used. Thus if a GregorianCalendar is passed in, the chronology used will be GJ, but if a Date is passed in the chronology will be ISO.

The recognised object types are defined in ConverterManager and include ReadableInstant, String, Calendar and Date.

Parameters:
instant - the datetime object, null means now
zone - the time zone, null means default time zone
Throws:
IllegalArgumentException - if the instant is invalid

DateTime

public DateTime(Object instant,
                Chronology chronology)
Constructs an instance from an Object that represents a datetime, using the specified chronology.

If the chronology is null, ISO in the default time zone is used. Any chronology implied by the object (such as GregorianCalendar does) is ignored.

The recognised object types are defined in ConverterManager and include ReadableInstant, String, Calendar and Date.

Parameters:
instant - the datetime object, null means now
chronology - the chronology, null means ISO in default zone
Throws:
IllegalArgumentException - if the instant is invalid

DateTime

public DateTime(int year,
                int monthOfYear,
                int dayOfMonth,
                int hourOfDay,
                int minuteOfHour,
                int secondOfMinute,
                int millisOfSecond)
Constructs an instance from datetime field values using ISOChronology in the default time zone.

Parameters:
year - the year
monthOfYear - the month of the year
dayOfMonth - the day of the month
hourOfDay - the hour of the day
minuteOfHour - the minute of the hour
secondOfMinute - the second of the minute
millisOfSecond - the millisecond of the second

DateTime

public DateTime(int year,
                int monthOfYear,
                int dayOfMonth,
                int hourOfDay,
                int minuteOfHour,
                int secondOfMinute,
                int millisOfSecond,
                DateTimeZone zone)
Constructs an instance from datetime field values using ISOChronology in the specified time zone.

If the specified time zone is null, the default zone is used.

Parameters:
year - the year
monthOfYear - the month of the year
dayOfMonth - the day of the month
hourOfDay - the hour of the day
minuteOfHour - the minute of the hour
secondOfMinute - the second of the minute
millisOfSecond - the millisecond of the second
zone - the time zone, null means default time zone

DateTime

public DateTime(int year,
                int monthOfYear,
                int dayOfMonth,
                int hourOfDay,
                int minuteOfHour,
                int secondOfMinute,
                int millisOfSecond,
                Chronology chronology)
Constructs an instance from datetime field values using the specified chronology.

If the chronology is null, ISOChronology in the default time zone is used.

Parameters:
year - the year
monthOfYear - the month of the year
dayOfMonth - the day of the month
hourOfDay - the hour of the day
minuteOfHour - the minute of the hour
secondOfMinute - the second of the minute
millisOfSecond - the millisecond of the second
chronology - the chronology, null means ISOChronology in default zone
Method Detail

toDateTime

public DateTime toDateTime()
Get this object as a DateTime by returning this.

Specified by:
toDateTime in interface ReadableDateTime
Overrides:
toDateTime in class AbstractInstant
Returns:
this

toDateTimeISO

public DateTime toDateTimeISO()
Get this object as a DateTime using ISOChronology in the default zone, returning this if possible.

Overrides:
toDateTimeISO in class AbstractInstant
Returns:
a DateTime using the same millis

toDateTime

public DateTime toDateTime(DateTimeZone zone)
Get this object as a DateTime, returning this if possible.

Overrides:
toDateTime in class AbstractInstant
Parameters:
zone - time zone to apply, or default if null
Returns:
a DateTime using the same millis

toDateTime

public DateTime toDateTime(Chronology chronology)
Get this object as a DateTime, returning this if possible.

Overrides:
toDateTime in class AbstractInstant
Parameters:
chronology - chronology to apply, or ISOChronology if null
Returns:
a DateTime using the same millis

withMillis

public DateTime withMillis(long newMillis)
Gets a copy of this datetime with different millis.

The returned object will be either be a new instance or this. Only the millis will change, the chronology and time zone are kept.

Parameters:
newMillis - the new millis, from 1970-01-01T00:00:00Z
Returns:
a copy of this datetime with different millis

withChronology

public DateTime withChronology(Chronology newChronology)
Gets a copy of this datetime with a different chronology.

The returned object will be either be a new instance or this. Only the chronology will change, the millis are kept.

Parameters:
newChronology - the new chronology, null means ISO default
Returns:
a copy of this datetime with a different chronology

withZone

public DateTime withZone(DateTimeZone newZone)
Gets a copy of this datetime with a different time zone, preserving the millisecond instant.

This method is useful for finding the local time in another timezone. For example, if this instant holds 12:30 in Europe/London, the result from this method with Europe/Paris would be 13:30.

The returned object will be a new instance of the same implementation type. This method changes the time zone, and does not change the millisecond instant, with the effect that the field values usually change. The returned object will be either be a new instance or this.

Parameters:
newZone - the new time zone
Returns:
a copy of this datetime with a different time zone
See Also:
withZoneRetainFields(org.joda.time.DateTimeZone)

withZoneRetainFields

public DateTime withZoneRetainFields(DateTimeZone newZone)
Gets a copy of this datetime with a different time zone, preserving the field values.

This method is useful for finding the millisecond time in another timezone. For example, if this instant holds 12:30 in Europe/London (ie. 12:30Z), the result from this method with Europe/Paris would be 12:30 (ie. 11:30Z).

The returned object will be a new instance of the same implementation type. This method changes the time zone and the millisecond instant to keep the field values the same. The returned object will be either be a new instance or this.

Parameters:
newZone - the new time zone, null means default
Returns:
a copy of this datetime with a different time zone
See Also:
withZone(org.joda.time.DateTimeZone)

withDate

public DateTime withDate(int year,
                         int monthOfYear,
                         int dayOfMonth)
Gets a copy of this datetime with the specified date, retaining the time fields.

If the date is already the date passed in, then this is returned.

To set a single field use the properties, for example:

 DateTime set = monthOfYear().setCopy(6);
 

Parameters:
year - the new year value
monthOfYear - the new monthOfYear value
dayOfMonth - the new dayOfMonth value
Returns:
a copy of this datetime with a different date
Throws:
IllegalArgumentException - if any value if invalid

withTime

public DateTime withTime(int hourOfDay,
                         int minuteOfHour,
                         int secondOfMinute,
                         int millisOfSecond)
Gets a copy of this datetime with the specified time, retaining the date fields.

If the time is already the time passed in, then this is returned.

To set a single field use the properties, for example:

 DateTime set = dt.hourOfDay().setCopy(6);
 

Parameters:
hourOfDay - the hour of the day
minuteOfHour - the minute of the hour
secondOfMinute - the second of the minute
millisOfSecond - the millisecond of the second
Returns:
a copy of this datetime with a different time
Throws:
IllegalArgumentException - if any value if invalid

withFields

public DateTime withFields(ReadablePartial partial)
Gets a copy of this datetime with the partial set of fields replacing those from this instance.

For example, if the partial is a TimeOfDay then the time fields would be changed in the returned instance. If the partial is null, then this is returned.

Parameters:
partial - the partial set of fields to apply to this datetime, null ignored
Returns:
a copy of this datetime with a different set of fields
Throws:
IllegalArgumentException - if any value is invalid

withField

public DateTime withField(DateTimeFieldType fieldType,
                          int value)
Gets a copy of this datetime with the specified field set to a new value.

For example, if the field type is hourOfDay then the hour of day field would be changed in the returned instance. If the field type is null, then this is returned.

These three lines are equivalent:

 DateTime updated = dt.withField(DateTimeFieldType.dayOfMonth(), 6);
 DateTime updated = dt.dayOfMonth().setCopy(6);
 DateTime updated = dt.property(DateTimeFieldType.dayOfMonth()).setCopy(6);
 

Parameters:
fieldType - the field type to set, not null
value - the value to set
Returns:
a copy of this datetime with the field set
Throws:
IllegalArgumentException - if the value is null or invalid

withFieldAdded

public DateTime withFieldAdded(DurationFieldType fieldType,
                               int amount)
Gets a copy of this datetime with the value of the specified field increased.

If the addition is zero or the field is null, then this is returned.

These three lines are equivalent:

 DateTime added = dt.withFieldAdded(DurationFieldType.years(), 6);
 DateTime added = dt.plusYears(6);
 DateTime added = dt.plus(Period.years(6));
 

Parameters:
fieldType - the field type to add to, not null
amount - the amount to add
Returns:
a copy of this datetime with the field updated
Throws:
IllegalArgumentException - if the value is null or invalid
ArithmeticException - if the new datetime exceeds the capacity of a long

withDurationAdded

public DateTime withDurationAdded(long durationToAdd,
                                  int scalar)
Gets a copy of this datetime with the specified duration added.

If the addition is zero, then this is returned.

Parameters:
durationToAdd - the duration to add to this one
scalar - the amount of times to add, such as -1 to subtract once
Returns:
a copy of this datetime with the duration added
Throws:
ArithmeticException - if the new datetime exceeds the capacity of a long

withDurationAdded

public DateTime withDurationAdded(ReadableDuration durationToAdd,
                                  int scalar)
Gets a copy of this datetime with the specified duration added.

If the addition is zero, then this is returned.

Parameters:
durationToAdd - the duration to add to this one, null means zero
scalar - the amount of times to add, such as -1 to subtract once
Returns:
a copy of this datetime with the duration added
Throws:
ArithmeticException - if the new datetime exceeds the capacity of a long

withPeriodAdded

public DateTime withPeriodAdded(ReadablePeriod period,
                                int scalar)
Gets a copy of this datetime with the specified period added.

If the addition is zero, then this is returned.

This method is typically used to add multiple copies of complex period instances. Adding one field is best achieved using methods like withFieldAdded(DurationFieldType, int) or plusYears(int).

Parameters:
period - the period to add to this one, null means zero
scalar - the amount of times to add, such as -1 to subtract once
Returns:
a copy of this datetime with the period added
Throws:
ArithmeticException - if the new datetime exceeds the capacity of a long

plus

public DateTime plus(long duration)
Gets a copy of this datetime with the specified duration added.

If the amount is zero or null, then this is returned.

Parameters:
duration - the duration, in millis, to add to this one
Returns:
a copy of this datetime with the duration added
Throws:
ArithmeticException - if the new datetime exceeds the capacity of a long

plus

public DateTime plus(ReadableDuration duration)
Gets a copy of this datetime with the specified duration added.

If the amount is zero or null, then this is returned.

Parameters:
duration - the duration to add to this one, null means zero
Returns:
a copy of this datetime with the duration added
Throws:
ArithmeticException - if the new datetime exceeds the capacity of a long

plus

public DateTime plus(ReadablePeriod period)
Gets a copy of this datetime with the specified period added.

If the amount is zero or null, then this is returned.

This method is typically used to add complex period instances. Adding one field is best achieved using methods like plusYears(int).

Parameters:
period - the duration to add to this one, null means zero
Returns:
a copy of this datetime with the period added
Throws:
ArithmeticException - if the new datetime exceeds the capacity of a long

plusYears

public DateTime plusYears(int years)
Returns a new datetime plus the specified number of years.

This datetime instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 DateTime added = dt.plusYears(6);
 DateTime added = dt.plus(Period.years(6));
 DateTime added = dt.withFieldAdded(DurationFieldType.years(), 6);
 

Parameters:
years - the amount of years to add, may be negative
Returns:
the new datetime plus the increased years
Since:
1.1

plusMonths

public DateTime plusMonths(int months)
Returns a new datetime plus the specified number of months.

This datetime instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 DateTime added = dt.plusMonths(6);
 DateTime added = dt.plus(Period.months(6));
 DateTime added = dt.withFieldAdded(DurationFieldType.months(), 6);
 

Parameters:
months - the amount of months to add, may be negative
Returns:
the new datetime plus the increased months
Since:
1.1

plusWeeks

public DateTime plusWeeks(int weeks)
Returns a new datetime plus the specified number of weeks.

This datetime instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 DateTime added = dt.plusWeeks(6);
 DateTime added = dt.plus(Period.weeks(6));
 DateTime added = dt.withFieldAdded(DurationFieldType.weeks(), 6);
 

Parameters:
weeks - the amount of weeks to add, may be negative
Returns:
the new datetime plus the increased weeks
Since:
1.1

plusDays

public DateTime plusDays(int days)
Returns a new datetime plus the specified number of days.

This datetime instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 DateTime added = dt.plusDays(6);
 DateTime added = dt.plus(Period.days(6));
 DateTime added = dt.withFieldAdded(DurationFieldType.days(), 6);
 

Parameters:
days - the amount of days to add, may be negative
Returns:
the new datetime plus the increased days
Since:
1.1

plusHours

public DateTime plusHours(int hours)
Returns a new datetime plus the specified number of hours.

This datetime instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 DateTime added = dt.plusHours(6);
 DateTime added = dt.plus(Period.hours(6));
 DateTime added = dt.withFieldAdded(DurationFieldType.hours(), 6);
 

Parameters:
hours - the amount of hours to add, may be negative
Returns:
the new datetime plus the increased hours
Since:
1.1

plusMinutes

public DateTime plusMinutes(int minutes)
Returns a new datetime plus the specified number of minutes.

This datetime instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 DateTime added = dt.plusMinutes(6);
 DateTime added = dt.plus(Period.minutes(6));
 DateTime added = dt.withFieldAdded(DurationFieldType.minutes(), 6);
 

Parameters:
minutes - the amount of minutes to add, may be negative
Returns:
the new datetime plus the increased minutes
Since:
1.1

plusSeconds

public DateTime plusSeconds(int seconds)
Returns a new datetime plus the specified number of seconds.

This datetime instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 DateTime added = dt.plusSeconds(6);
 DateTime added = dt.plus(Period.seconds(6));
 DateTime added = dt.withFieldAdded(DurationFieldType.seconds(), 6);
 

Parameters:
seconds - the amount of seconds to add, may be negative
Returns:
the new datetime plus the increased seconds
Since:
1.1

plusMillis

public DateTime plusMillis(int millis)
Returns a new datetime plus the specified number of millis.

This datetime instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 DateTime added = dt.plusMillis(6);
 DateTime added = dt.plus(Period.millis(6));
 DateTime added = dt.withFieldAdded(DurationFieldType.millis(), 6);
 

Parameters:
millis - the amount of millis to add, may be negative
Returns:
the new datetime plus the increased millis
Since:
1.1

minus

public DateTime minus(long duration)
Gets a copy of this datetime with the specified duration take away.

If the amount is zero or null, then this is returned.

Parameters:
duration - the duration, in millis, to reduce this instant by
Returns:
a copy of this datetime with the duration taken away
Throws:
ArithmeticException - if the new datetime exceeds the capacity of a long

minus

public DateTime minus(ReadableDuration duration)
Gets a copy of this datetime with the specified duration take away.

If the amount is zero or null, then this is returned.

Parameters:
duration - the duration to reduce this instant by
Returns:
a copy of this datetime with the duration taken away
Throws:
ArithmeticException - if the new datetime exceeds the capacity of a long

minus

public DateTime minus(ReadablePeriod period)
Gets a copy of this datetime with the specified period take away.

If the amount is zero or null, then this is returned.

This method is typically used to subtract complex period instances. Subtracting one field is best achieved using methods like minusYears(int).

Parameters:
period - the period to reduce this instant by
Returns:
a copy of this datetime with the period taken away
Throws:
ArithmeticException - if the new datetime exceeds the capacity of a long

minusYears

public DateTime minusYears(int years)
Returns a new datetime minus the specified number of years.

This datetime instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 DateTime subtracted = dt.minusYears(6);
 DateTime subtracted = dt.minus(Period.years(6));
 DateTime subtracted = dt.withFieldAdded(DurationFieldType.years(), -6);
 

Parameters:
years - the amount of years to subtract, may be negative
Returns:
the new datetime minus the increased years
Since:
1.1

minusMonths

public DateTime minusMonths(int months)
Returns a new datetime minus the specified number of months.

This datetime instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 DateTime subtracted = dt.minusMonths(6);
 DateTime subtracted = dt.minus(Period.months(6));
 DateTime subtracted = dt.withFieldAdded(DurationFieldType.months(), -6);
 

Parameters:
months - the amount of months to subtract, may be negative
Returns:
the new datetime minus the increased months
Since:
1.1

minusWeeks

public DateTime minusWeeks(int weeks)
Returns a new datetime minus the specified number of weeks.

This datetime instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 DateTime subtracted = dt.minusWeeks(6);
 DateTime subtracted = dt.minus(Period.weeks(6));
 DateTime subtracted = dt.withFieldAdded(DurationFieldType.weeks(), -6);
 

Parameters:
weeks - the amount of weeks to subtract, may be negative
Returns:
the new datetime minus the increased weeks
Since:
1.1

minusDays

public DateTime minusDays(int days)
Returns a new datetime minus the specified number of days.

This datetime instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 DateTime subtracted = dt.minusDays(6);
 DateTime subtracted = dt.minus(Period.days(6));
 DateTime subtracted = dt.withFieldAdded(DurationFieldType.days(), -6);
 

Parameters:
days - the amount of days to subtract, may be negative
Returns:
the new datetime minus the increased days
Since:
1.1

minusHours

public DateTime minusHours(int hours)
Returns a new datetime minus the specified number of hours.

This datetime instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 DateTime subtracted = dt.minusHours(6);
 DateTime subtracted = dt.minus(Period.hours(6));
 DateTime subtracted = dt.withFieldAdded(DurationFieldType.hours(), -6);
 

Parameters:
hours - the amount of hours to subtract, may be negative
Returns:
the new datetime minus the increased hours
Since:
1.1

minusMinutes

public DateTime minusMinutes(int minutes)
Returns a new datetime minus the specified number of minutes.

This datetime instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 DateTime subtracted = dt.minusMinutes(6);
 DateTime subtracted = dt.minus(Period.minutes(6));
 DateTime subtracted = dt.withFieldAdded(DurationFieldType.minutes(), -6);
 

Parameters:
minutes - the amount of minutes to subtract, may be negative
Returns:
the new datetime minus the increased minutes
Since:
1.1

minusSeconds

public DateTime minusSeconds(int seconds)
Returns a new datetime minus the specified number of seconds.

This datetime instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 DateTime subtracted = dt.minusSeconds(6);
 DateTime subtracted = dt.minus(Period.seconds(6));
 DateTime subtracted = dt.withFieldAdded(DurationFieldType.seconds(), -6);
 

Parameters:
seconds - the amount of seconds to subtract, may be negative
Returns:
the new datetime minus the increased seconds
Since:
1.1

minusMillis

public DateTime minusMillis(int millis)
Returns a new datetime minus the specified number of millis.

This datetime instance is immutable and unaffected by this method call.

The following three lines are identical in effect:

 DateTime subtracted = dt.minusMillis(6);
 DateTime subtracted = dt.minus(Period.millis(6));
 DateTime subtracted = dt.withFieldAdded(DurationFieldType.millis(), -6);
 

Parameters:
millis - the amount of millis to subtract, may be negative
Returns:
the new datetime minus the increased millis
Since:
1.1

property

public DateTime.Property property(DateTimeFieldType type)
Gets the property object for the specified type, which contains many useful methods.

Parameters:
type - the field type to get the chronology for
Returns:
the property object
Throws:
IllegalArgumentException - if the field is null or unsupported

toDateMidnight

public DateMidnight toDateMidnight()
Converts this object to a DateMidnight using the same millis and chronology.

Returns:
a DateMidnight using the same millis and chronology

toYearMonthDay

public YearMonthDay toYearMonthDay()
Converts this object to a YearMonthDay using the same millis and chronology.

Returns:
a YearMonthDay using the same millis and chronology

toTimeOfDay

public TimeOfDay toTimeOfDay()
Converts this object to a TimeOfDay using the same millis and chronology.

Returns:
a TimeOfDay using the same millis and chronology

era

public DateTime.Property era()
Get the era property.

Returns:
the era property

centuryOfEra

public DateTime.Property centuryOfEra()
Get the century of era property.

Returns:
the year of era property

yearOfCentury

public DateTime.Property yearOfCentury()
Get the year of century property.

Returns:
the year of era property

yearOfEra

public DateTime.Property yearOfEra()
Get the year of era property.

Returns:
the year of era property

year

public DateTime.Property year()
Get the year property.

Returns:
the year property

weekyear

public DateTime.Property weekyear()
Get the year of a week based year property.

Returns:
the year of a week based year property

monthOfYear

public DateTime.Property monthOfYear()
Get the month of year property.

Returns:
the month of year property

weekOfWeekyear

public DateTime.Property weekOfWeekyear()
Get the week of a week based year property.

Returns:
the week of a week based year property

dayOfYear

public DateTime.Property dayOfYear()
Get the day of year property.

Returns:
the day of year property

dayOfMonth

public DateTime.Property dayOfMonth()
Get the day of month property.

Returns:
the day of month property

dayOfWeek

public DateTime.Property dayOfWeek()
Get the day of week property.

Returns:
the day of week property

hourOfDay

public DateTime.Property hourOfDay()
Get the hour of day field property

Returns:
the hour of day property

minuteOfDay

public DateTime.Property minuteOfDay()
Get the minute of day property

Returns:
the minute of day property

minuteOfHour

public DateTime.Property minuteOfHour()
Get the minute of hour field property

Returns:
the minute of hour property

secondOfDay

public DateTime.Property secondOfDay()
Get the second of day property

Returns:
the second of day property

secondOfMinute

public DateTime.Property secondOfMinute()
Get the second of minute field property

Returns:
the second of minute property

millisOfDay

public DateTime.Property millisOfDay()
Get the millis of day property

Returns:
the millis of day property

millisOfSecond

public DateTime.Property millisOfSecond()
Get the millis of second property

Returns:
the millis of second property


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