java.lang.Object | ||||
↳ | org.joda.time.base.AbstractInstant | |||
↳ | org.joda.time.base.AbstractDateTime | |||
↳ | org.joda.time.base.BaseDateTime | |||
↳ | org.joda.time.MutableDateTime |
MutableDateTime is the standard implementation of a modifiable 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 accessed in two ways:
getHourOfDay()
hourOfDay().get()
MutableDateTime is mutable and not thread-safe, unless concurrent threads are not invoking mutator methods.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
MutableDateTime.Property | MutableDateTime.Property binds a MutableDateTime to a DateTimeField allowing powerful datetime functionality to be easily accessed. |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | ROUND_CEILING | Rounding mode as described by roundCeiling(long) |
|||||||||
int | ROUND_FLOOR | Rounding mode as described by roundFloor(long) |
|||||||||
int | ROUND_HALF_CEILING | Rounding mode as described by roundHalfCeiling(long) |
|||||||||
int | ROUND_HALF_EVEN | Rounding mode as described by roundHalfEven(long) |
|||||||||
int | ROUND_HALF_FLOOR | Rounding mode as described by roundHalfFloor(long) |
|||||||||
int | ROUND_NONE | Rounding is disabled |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs an instance set to the current system millisecond time
using
ISOChronology in the default time zone. | |||||||||||
Constructs an instance set to the current system millisecond time
using
ISOChronology in the specified time zone. | |||||||||||
Constructs an instance set to the current system millisecond time
using the specified chronology.
| |||||||||||
Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z
using
ISOChronology in the default time zone. | |||||||||||
Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z
using
ISOChronology in the specified time zone. | |||||||||||
Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z
using the specified chronology.
| |||||||||||
Constructs an instance from an Object that represents a datetime.
| |||||||||||
Constructs an instance from an Object that represents a datetime,
forcing the time zone to that specified.
| |||||||||||
Constructs an instance from an Object that represents a datetime,
using the specified chronology.
| |||||||||||
Constructs an instance from datetime field values
using
ISOChronology in the default time zone. | |||||||||||
Constructs an instance from datetime field values
using
ISOChronology in the specified time zone. | |||||||||||
Constructs an instance from datetime field values
using the specified chronology.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds a duration to this instant.
| |||||||||||
Add an amount of time to the datetime.
| |||||||||||
Adds a period to this instant.
| |||||||||||
Adds a period to this instant specifying how many times to add.
| |||||||||||
Adds a duration to this instant specifying how many times to add.
| |||||||||||
Adds to the instant specifying the duration and multiple to add.
| |||||||||||
Add a number of days to the date.
| |||||||||||
Add a number of hours to the date.
| |||||||||||
Add a number of milliseconds to the date.
| |||||||||||
Add a number of minutes to the date.
| |||||||||||
Add a number of months to the date.
| |||||||||||
Add a number of seconds to the date.
| |||||||||||
Add a number of weeks to the date.
| |||||||||||
Add a number of weekyears to the date.
| |||||||||||
Add a number of years to the date.
| |||||||||||
Get the century of era property.
| |||||||||||
Clone this object.
| |||||||||||
Clone this object without having to cast the returned object.
| |||||||||||
Get the day of month property.
| |||||||||||
Get the day of week property.
| |||||||||||
Get the day of year property.
| |||||||||||
Get the era property.
| |||||||||||
Gets the field used for rounding this instant, returning null if rounding
is not enabled.
| |||||||||||
Gets the rounding mode for this instant, returning ROUND_NONE if rounding
is not enabled.
| |||||||||||
Get the hour of day field property
| |||||||||||
Get the millis of day property
| |||||||||||
Get the millis of second property
| |||||||||||
Get the minute of day property
| |||||||||||
Get the minute of hour field property
| |||||||||||
Get the month of year property.
| |||||||||||
Gets the property object for the specified type, which contains many useful methods.
| |||||||||||
Get the second of day property
| |||||||||||
Get the second of minute field property
| |||||||||||
Sets the value of one of the fields of the instant, such as hourOfDay.
| |||||||||||
Set the chronology of the datetime.
| |||||||||||
Set the date from milliseconds.
| |||||||||||
Set the date from fields.
| |||||||||||
Set the date from another instant.
| |||||||||||
Set the date and time from fields.
| |||||||||||
Set the day of the month to the specified value.
| |||||||||||
Set the day of week to the specified value.
| |||||||||||
Set the day of year to the specified value.
| |||||||||||
Set the hour of the day to the specified value.
| |||||||||||
Sets the millisecond instant of this instant from another.
| |||||||||||
Set the milliseconds of the datetime.
| |||||||||||
Set the millis of the day to the specified value.
| |||||||||||
Set the millis of the second to the specified value.
| |||||||||||
Set the minute of the day to the specified value.
| |||||||||||
Set the minute of the hour to the specified value.
| |||||||||||
Set the month of the year to the specified value.
| |||||||||||
Sets the status of rounding to use the specified field and ROUND_FLOOR mode.
| |||||||||||
Sets the status of rounding to use the specified field and mode.
| |||||||||||
Set the second of the day to the specified value.
| |||||||||||
Set the second of the minute to the specified value.
| |||||||||||
Set the time from fields.
| |||||||||||
Set the time from milliseconds.
| |||||||||||
Set the time from another instant.
| |||||||||||
Set the week of weekyear to the specified value.
| |||||||||||
Set the weekyear to the specified value.
| |||||||||||
Set the year to the specified value.
| |||||||||||
Sets the time zone of the datetime, changing the chronology and field values.
| |||||||||||
Sets the time zone of the datetime, changing the chronology and millisecond.
| |||||||||||
Output the date time in ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSSZZ).
| |||||||||||
Get the week of a week based year property.
| |||||||||||
Get the year of a week based year property.
| |||||||||||
Get the year property.
| |||||||||||
Get the year of century property.
| |||||||||||
Get the year of era property.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.joda.time.base.BaseDateTime
| |||||||||||
From class
org.joda.time.base.AbstractDateTime
| |||||||||||
From class
org.joda.time.base.AbstractInstant
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.lang.Comparable
| |||||||||||
From interface
org.joda.time.ReadWritableDateTime
| |||||||||||
From interface
org.joda.time.ReadWritableInstant
| |||||||||||
From interface
org.joda.time.ReadableDateTime
| |||||||||||
From interface
org.joda.time.ReadableInstant
|
Rounding mode as described by roundCeiling(long)
Rounding mode as described by roundFloor(long)
Rounding mode as described by roundHalfCeiling(long)
Rounding mode as described by roundHalfEven(long)
Rounding mode as described by roundHalfFloor(long)
Rounding is disabled
Constructs an instance set to the current system millisecond time
using ISOChronology
in the default time 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.
zone | the time zone, null means default zone |
---|
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.
chronology | the chronology, null means ISOChronology in default zone |
---|
Constructs an instance set to the milliseconds from 1970-01-01T00:00:00Z
using ISOChronology
in the default time zone.
instant | the milliseconds from 1970-01-01T00:00:00Z |
---|
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.
instant | the milliseconds from 1970-01-01T00:00:00Z |
---|---|
zone | the time zone, null means default zone |
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.
instant | the milliseconds from 1970-01-01T00:00:00Z |
---|---|
chronology | the chronology, null means ISOChronology in default zone |
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.
instant | the datetime object, null means now |
---|
IllegalArgumentException | if the instant is invalid |
---|
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.
instant | the datetime object, null means now |
---|---|
zone | the time zone, null means default time zone |
IllegalArgumentException | if the instant is invalid |
---|
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.
instant | the datetime object, null means now |
---|---|
chronology | the chronology, null means ISOChronology in default zone |
IllegalArgumentException | if the instant is invalid |
---|
Constructs an instance from datetime field values
using ISOChronology
in the default time zone.
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 |
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.
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 |
Constructs an instance from datetime field values using the specified chronology.
If the chronology is null, ISOChronology
in the default time zone is used.
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 |
Adds a duration to this instant.
This will typically change the value of most fields.
duration | the duration to add, null means add zero |
---|
ArithmeticException | if the result exceeds the capacity of the instant |
---|
Add an amount of time to the datetime.
duration | the millis to add |
---|
ArithmeticException | if the result exceeds the capacity of the instant |
---|
Adds a period to this instant.
This will typically change the value of most fields.
period | the period to add, null means add zero |
---|
ArithmeticException | if the result exceeds the capacity of the instant |
---|
Adds a period to this instant specifying how many times to add.
This will typically change the value of most fields.
period | the period to add, null means add zero |
---|---|
scalar | direction and amount to add, which may be negative |
ArithmeticException | if the result exceeds the capacity of the instant |
---|
Adds a duration to this instant specifying how many times to add.
This will typically change the value of most fields.
duration | the duration to add, null means add zero |
---|---|
scalar | direction and amount to add, which may be negative |
ArithmeticException | if the result exceeds the capacity of the instant |
---|
Adds to the instant specifying the duration and multiple to add.
type | a field type, usually obtained from DateTimeFieldType, not null |
---|---|
amount | the amount to add of this duration |
IllegalArgumentException | if the value is null or invalid |
---|---|
ArithmeticException | if the result exceeds the capacity of the instant |
Add a number of days to the date.
days | the days to add |
---|
IllegalArgumentException | if the value is invalid |
---|
Add a number of hours to the date.
hours | the hours to add |
---|
IllegalArgumentException | if the value is invalid |
---|
Add a number of milliseconds to the date. The implementation of this
method differs from the add(long)
method in that a
DateTimeField performs the addition.
millis | the milliseconds to add |
---|
IllegalArgumentException | if the value is invalid |
---|
Add a number of minutes to the date.
minutes | the minutes to add |
---|
IllegalArgumentException | if the value is invalid |
---|
Add a number of months to the date.
months | the months to add |
---|
IllegalArgumentException | if the value is invalid |
---|
Add a number of seconds to the date.
seconds | the seconds to add |
---|
IllegalArgumentException | if the value is invalid |
---|
Add a number of weeks to the date.
weeks | the weeks to add |
---|
IllegalArgumentException | if the value is invalid |
---|
Add a number of weekyears to the date.
weekyears | the weekyears to add |
---|
IllegalArgumentException | if the value is invalid |
---|
Add a number of years to the date.
years | the years to add |
---|
IllegalArgumentException | if the value is invalid |
---|
Get the century of era property.
Clone this object without having to cast the returned object.
Get the day of month property.
The values for day of month are defined in DateTimeConstants
.
Get the day of week property.
The values for day of week are defined in DateTimeConstants
.
Get the day of year property.
Gets the field used for rounding this instant, returning null if rounding is not enabled.
Gets the rounding mode for this instant, returning ROUND_NONE if rounding is not enabled.
Get the hour of day field property
Get the millis of day property
Get the millis of second property
Get the minute of day property
Get the minute of hour field property
Get the month of year property.
Gets the property object for the specified type, which contains many useful methods.
type | the field type to get the chronology for |
---|
IllegalArgumentException | if the field is null or unsupported |
---|
Get the second of day property
Get the second of minute field property
Sets the value of one of the fields of the instant, such as hourOfDay.
type | a field type, usually obtained from DateTimeFieldType, not null |
---|---|
value | the value to set the field to |
IllegalArgumentException | if the value is null or invalid |
---|
Set the chronology of the datetime.
All changes to the chronology occur via this method.
chronology | the chronology to use, null means ISOChronology in default zone |
---|
Set the date from milliseconds. The time part of this object will be unaffected.
instant | an instant to copy the date from, time part ignored |
---|
IllegalArgumentException | if the value is invalid |
---|
Set the date from fields. The time part of this object will be unaffected.
year | the year |
---|---|
monthOfYear | the month of the year |
dayOfMonth | the day of the month |
IllegalArgumentException | if the value is invalid |
---|
Set the date from another instant. The time part of this object will be unaffected.
instant | an instant to copy the date from, time part ignored |
---|
IllegalArgumentException | if the object is invalid |
---|
Set the date and time from fields.
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 |
IllegalArgumentException | if the value is invalid |
---|
Set the day of the month to the specified value.
dayOfMonth | the day of the month |
---|
IllegalArgumentException | if the value is invalid |
---|
Set the day of week to the specified value.
dayOfWeek | the day of the week |
---|
IllegalArgumentException | if the value is invalid |
---|
Set the day of year to the specified value.
dayOfYear | the day of the year |
---|
IllegalArgumentException | if the value is invalid |
---|
Set the hour of the day to the specified value.
hourOfDay | the hour of day |
---|
IllegalArgumentException | if the value is invalid |
---|
Sets the millisecond instant of this instant from another.
This method does not change the chronology of this instant, just the millisecond instant.
instant | the instant to use, null means now |
---|
Set the milliseconds of the datetime.
All changes to the millisecond field occurs via this method.
instant | the milliseconds since 1970-01-01T00:00:00Z to set the datetime to |
---|
Set the millis of the day to the specified value.
millisOfDay | the millis of day |
---|
IllegalArgumentException | if the value is invalid |
---|
Set the millis of the second to the specified value.
millisOfSecond | the millis of second |
---|
IllegalArgumentException | if the value is invalid |
---|
Set the minute of the day to the specified value.
minuteOfDay | the minute of day |
---|
IllegalArgumentException | if the value is invalid |
---|
Set the minute of the hour to the specified value.
minuteOfHour | the minute of hour |
---|
IllegalArgumentException | if the value is invalid |
---|
Set the month of the year to the specified value.
monthOfYear | the month of the year |
---|
IllegalArgumentException | if the value is invalid |
---|
Sets the status of rounding to use the specified field and ROUND_FLOOR mode. A null field will disable rounding. Once set, the instant is then rounded using the new field and mode.
Enabling rounding will cause all subsequent calls to setMillis(long)
to be rounded. This can be used to control the precision of the instant,
for example by setting a rounding field of minuteOfDay, the seconds and
milliseconds will always be zero.
field | rounding field or null to disable |
---|
Sets the status of rounding to use the specified field and mode. A null field or mode of ROUND_NONE will disable rounding. Once set, the instant is then rounded using the new field and mode.
Enabling rounding will cause all subsequent calls to setMillis(long)
to be rounded. This can be used to control the precision of the instant,
for example by setting a rounding field of minuteOfDay, the seconds and
milliseconds will always be zero.
field | rounding field or null to disable |
---|---|
mode | rounding mode or ROUND_NONE to disable |
IllegalArgumentException | if mode is unknown, no exception if field is null |
---|
Set the second of the day to the specified value.
secondOfDay | the second of day |
---|
IllegalArgumentException | if the value is invalid |
---|
Set the second of the minute to the specified value.
secondOfMinute | the second of minute |
---|
IllegalArgumentException | if the value is invalid |
---|
Set the time from fields. The date part of this object will be unaffected.
hour | the hour |
---|---|
minuteOfHour | the minute of the hour |
secondOfMinute | the second of the minute |
millisOfSecond | the millisecond of the second |
IllegalArgumentException | if the value is invalid |
---|
Set the time from milliseconds. The date part of this object will be unaffected.
millis | an instant to copy the time from, date part ignored |
---|
IllegalArgumentException | if the value is invalid |
---|
Set the time from another instant. The date part of this object will be unaffected.
instant | an instant to copy the time from, date part ignored |
---|
IllegalArgumentException | if the object is invalid |
---|
Set the week of weekyear to the specified value.
weekOfWeekyear | the week of the weekyear |
---|
IllegalArgumentException | if the value is invalid |
---|
Set the weekyear to the specified value.
weekyear | the weekyear |
---|
IllegalArgumentException | if the value is invalid |
---|
Set the year to the specified value.
year | the year |
---|
IllegalArgumentException | if the value is invalid |
---|
Sets the time zone of the datetime, changing the chronology and field values.
Changing the zone using this method retains the millisecond instant. The millisecond instant is adjusted in the new zone to compensate. chronology. Setting the time zone does not affect the millisecond value of this instant.
If the chronology already has this time zone, no change occurs.
newZone | the time zone to use, null means default zone |
---|
Sets the time zone of the datetime, changing the chronology and millisecond.
Changing the zone using this method retains the field values. The millisecond instant is adjusted in the new zone to compensate.
If the chronology already has this time zone, no change occurs.
newZone | the time zone to use, null means default zone |
---|
Output the date time in ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSSZZ).
Get the week of a week based year property.
Get the year of a week based year property.
Get the year of century property.
Get the year of era property.