java.lang.Object | |||
↳ | org.joda.time.base.AbstractPartial | ||
↳ | org.joda.time.base.BaseLocal | ||
↳ | org.joda.time.LocalDateTime |
LocalDateTime is an unmodifiable datetime class representing a datetime without a time zone.
LocalDateTime implements the ReadablePartial
interface.
To do this, certain methods focus on key fields Year, MonthOfYear,
DayOfYear and MillisOfDay.
However, all fields may in fact be queried.
Internally, LocalDateTime uses a single millisecond-based value to represent the local datetime. This value is only used internally and is not exposed to applications.
Calculations on LocalDateTime are performed using a Chronology
.
This chronology will be set internally to be in the UTC time zone
for all calculations.
Each individual field can be queried in two ways:
getHourOfDay()
hourOfDay().get()
LocalDateTime is thread-safe and immutable, provided that the Chronology is as well. All standard Chronology classes supplied are thread-safe and immutable.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
LocalDateTime.Property | LocalDateTime.Property binds a LocalDateTime to a DateTimeField allowing powerful datetime functionality to be easily accessed. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs an instance set to the current local time evaluated using
ISO chronology in the default zone.
| |||||||||||
Constructs an instance set to the current local time evaluated using
ISO chronology in the specified zone.
| |||||||||||
Constructs an instance set to the current local time evaluated using
specified chronology.
| |||||||||||
Constructs an instance set to the local time defined by the specified
instant evaluated using ISO chronology in the default zone.
| |||||||||||
Constructs an instance set to the local time defined by the specified
instant evaluated using ISO chronology in the specified zone.
| |||||||||||
Constructs an instance set to the local time defined by the specified
instant evaluated 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 set to the specified date and time
using
ISOChronology . | |||||||||||
Constructs an instance set to the specified date and time
using
ISOChronology . | |||||||||||
Constructs an instance set to the specified date and time
using
ISOChronology . | |||||||||||
Constructs an instance set to the specified date and time
using the specified chronology, whose zone is ignored.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Get the century of era property which provides access to advanced functionality.
| |||||||||||
Compares this partial with another returning an integer
indicating the order.
| |||||||||||
Get the day of month property which provides access to advanced functionality.
| |||||||||||
Get the day of week property which provides access to advanced functionality.
| |||||||||||
Get the day of year property which provides access to advanced functionality.
| |||||||||||
Compares this ReadablePartial with another returning true if the chronology,
field types and values are equal.
| |||||||||||
Get the era property which provides access to advanced functionality.
| |||||||||||
Constructs a LocalDateTime from a
java.util.Calendar
using exactly the same field values. | |||||||||||
Constructs a LocalDateTime from a
java.util.Date
using exactly the same field values. | |||||||||||
Get the value of one of the fields of a datetime.
| |||||||||||
Get the year of era field value.
| |||||||||||
Gets the chronology of the datetime.
| |||||||||||
Get the day of month field value.
| |||||||||||
Get the day of week field value.
| |||||||||||
Get the day of year field value.
| |||||||||||
Get the era field value.
| |||||||||||
Get the hour of day field value.
| |||||||||||
Get the millis of day field value.
| |||||||||||
Get the millis of second field value.
| |||||||||||
Get the minute of hour field value.
| |||||||||||
Get the month of year field value.
| |||||||||||
Get the second of minute field value.
| |||||||||||
Gets the value of the field at the specifed index.
| |||||||||||
Get the week of weekyear field value.
| |||||||||||
Get the weekyear field value.
| |||||||||||
Get the year field value.
| |||||||||||
Get the year of century field value.
| |||||||||||
Get the year of era field value.
| |||||||||||
Get the hour of day field property which provides access to advanced functionality.
| |||||||||||
Checks if the duration type specified is supported by this
local datetime and chronology.
| |||||||||||
Checks if the field type specified is supported by this
local datetime and chronology.
| |||||||||||
Get the millis of day property which provides access to advanced functionality.
| |||||||||||
Get the millis of second property which provides access to advanced functionality.
| |||||||||||
Returns a copy of this datetime with the specified period taken away.
| |||||||||||
Returns a copy of this datetime with the specified duration taken away.
| |||||||||||
Returns a copy of this datetime minus the specified number of days.
| |||||||||||
Returns a copy of this datetime minus the specified number of hours.
| |||||||||||
Returns a copy of this datetime minus the specified number of millis.
| |||||||||||
Returns a copy of this datetime minus the specified number of minutes.
| |||||||||||
Returns a copy of this datetime minus the specified number of months.
| |||||||||||
Returns a copy of this datetime minus the specified number of seconds.
| |||||||||||
Returns a copy of this datetime minus the specified number of weeks.
| |||||||||||
Returns a copy of this datetime minus the specified number of years.
| |||||||||||
Get the minute of hour field property which provides access to advanced functionality.
| |||||||||||
Get the month of year property which provides access to advanced functionality.
| |||||||||||
Returns a copy of this datetime with the specified period added.
| |||||||||||
Returns a copy of this datetime with the specified duration added.
| |||||||||||
Returns a copy of this datetime plus the specified number of days.
| |||||||||||
Returns a copy of this datetime plus the specified number of hours.
| |||||||||||
Returns a copy of this datetime plus the specified number of millis.
| |||||||||||
Returns a copy of this datetime plus the specified number of minutes.
| |||||||||||
Returns a copy of this datetime plus the specified number of months.
| |||||||||||
Returns a copy of this datetime plus the specified number of seconds.
| |||||||||||
Returns a copy of this datetime plus the specified number of weeks.
| |||||||||||
Returns a copy of this datetime plus the specified number of years.
| |||||||||||
Gets the property object for the specified type, which contains many
useful methods.
| |||||||||||
Get the second of minute field property which provides access to advanced functionality.
| |||||||||||
Gets the number of fields in this partial, which is four.
| |||||||||||
Converts this object to a DateTime using the specified zone.
| |||||||||||
Converts this object to a DateTime using the default zone.
| |||||||||||
Converts this object to a LocalDate with the same date and chronology.
| |||||||||||
Converts this object to a LocalTime with the same time and chronology.
| |||||||||||
Output the date using the specified format pattern.
| |||||||||||
Output the date using the specified format pattern.
| |||||||||||
Output the date time in ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSS).
| |||||||||||
Get the week of a week based year property which provides access to advanced functionality.
| |||||||||||
Get the weekyear property which provides access to advanced functionality.
| |||||||||||
Returns a copy of this datetime with the century of era field updated.
| |||||||||||
Returns a copy of this datetime with the specified date,
retaining the time fields.
| |||||||||||
Returns a copy of this datetime with the day of month field updated.
| |||||||||||
Returns a copy of this datetime with the day of week field updated.
| |||||||||||
Returns a copy of this datetime with the day of year field updated.
| |||||||||||
Returns a copy of this datetime with the specified duration added.
| |||||||||||
Returns a copy of this datetime with the era field updated.
| |||||||||||
Returns a copy of this datetime with the specified field set to a new value.
| |||||||||||
Returns a copy of this datetime with the value of the specified
field increased.
| |||||||||||
Returns a copy of this datetime with the partial set of fields
replacing those from this instance.
| |||||||||||
Returns a copy of this datetime with the hour of day field updated.
| |||||||||||
Returns a copy of this datetime with the millis of day field updated.
| |||||||||||
Returns a copy of this datetime with the millis of second field updated.
| |||||||||||
Returns a copy of this datetime with the minute of hour field updated.
| |||||||||||
Returns a copy of this datetime with the month of year field updated.
| |||||||||||
Returns a copy of this datetime with the specified period added.
| |||||||||||
Returns a copy of this datetime with the second of minute field updated.
| |||||||||||
Returns a copy of this datetime with the specified time,
retaining the date fields.
| |||||||||||
Returns a copy of this datetime with the week of weekyear field updated.
| |||||||||||
Returns a copy of this datetime with the weekyear field updated.
| |||||||||||
Returns a copy of this datetime with the year field updated.
| |||||||||||
Returns a copy of this datetime with the year of century field updated.
| |||||||||||
Returns a copy of this datetime with the year of era field updated.
| |||||||||||
Get the year property which provides access to advanced functionality.
| |||||||||||
Get the year of century property which provides access to advanced functionality.
| |||||||||||
Get the year of era property which provides access to advanced functionality.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Gets the field for a specific index in the chronology specified.
| |||||||||||
Gets the milliseconds of the datetime instant from the Java epoch
of 1970-01-01T00:00:00 (not fixed to any specific time zone).
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
org.joda.time.base.BaseLocal
| |||||||||||
From class
org.joda.time.base.AbstractPartial
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.lang.Comparable
| |||||||||||
From interface
org.joda.time.ReadablePartial
|
Constructs an instance set to the current local time evaluated using ISO chronology in the default zone.
Once the constructor is completed, the zone is no longer used.
Constructs an instance set to the current local time evaluated using ISO chronology in the specified zone.
If the specified time zone is null, the default zone is used. Once the constructor is completed, the zone is no longer used.
zone | the time zone, null means default zone |
---|
Constructs an instance set to the current local time evaluated using specified chronology.
If the chronology is null, ISO chronology in the default time zone is used. Once the constructor is completed, the zone is no longer used.
chronology | the chronology, null means ISOChronology in default zone |
---|
Constructs an instance set to the local time defined by the specified instant evaluated using ISO chronology in the default zone.
Once the constructor is completed, the zone is no longer used.
instant | the milliseconds from 1970-01-01T00:00:00Z |
---|
Constructs an instance set to the local time defined by the specified instant evaluated using ISO chronology in the specified zone.
If the specified time zone is null, the default zone is used. Once the constructor is completed, the zone is no longer used.
instant | the milliseconds from 1970-01-01T00:00:00Z |
---|---|
zone | the time zone, null means default zone |
Constructs an instance set to the local time defined by the specified instant evaluated using the specified chronology.
If the chronology is null, ISO chronology in the default zone is used. Once the constructor is completed, the zone is no longer 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 contains no chronology, ISOChronology
is used.
If the object contains no time zone, the default zone is used.
Once the constructor is completed, the zone is no longer used.
The recognised object types are defined in
ConverterManager
and
include ReadablePartial, ReadableInstant, String, Calendar and Date.
The String formats are described by localDateOptionalTimeParser()
.
The default String converter ignores the zone and only parses the field values.
instant | the datetime object |
---|
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 contains no chronology, ISOChronology
is used.
If the specified time zone is null, the default zone is used.
Once the constructor is completed, the zone is no longer used.
The recognised object types are defined in
ConverterManager
and
include ReadablePartial, ReadableInstant, String, Calendar and Date.
The String formats are described by localDateOptionalTimeParser()
.
The default String converter ignores the zone and only parses the field values.
instant | the datetime object |
---|---|
zone | the 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. Once the constructor is completed, the zone is no longer used.
The recognised object types are defined in
ConverterManager
and
include ReadablePartial, ReadableInstant, String, Calendar and Date.
The String formats are described by localDateOptionalTimeParser()
.
The default String converter ignores the zone and only parses the field values.
instant | the datetime object |
---|---|
chronology | the chronology |
IllegalArgumentException | if the instant is invalid |
---|
Constructs an instance set to the specified date and time
using ISOChronology
.
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 |
Constructs an instance set to the specified date and time
using ISOChronology
.
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 |
Constructs an instance set to the specified date and time
using ISOChronology
.
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 set to the specified date and time using the specified chronology, whose zone is ignored.
If the chronology is null, ISOChronology
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 |
Get the century of era property which provides access to advanced functionality.
Compares this partial with another returning an integer indicating the order.
The fields are compared in order, from largest to smallest. The first field that is non-equal is used to determine the result.
The specified object must be a partial instance whose field types match those of this partial.
NOTE: This implementation violates the Comparable contract. This method will accept any instance of ReadablePartial as input. However, it is possible that some implementations of ReadablePartial exist that do not extend AbstractPartial, and thus will throw a ClassCastException if compared in the opposite direction. The cause of this problem is that ReadablePartial doesn't define the compareTo() method, however we can't change that until v2.0.
partial | an object to check against |
---|
ClassCastException | if the partial is the wrong class or if it has field types that don't match |
---|---|
NullPointerException | if the partial is null |
Get the day of month property which provides access to advanced functionality.
Get the day of week property which provides access to advanced functionality.
Get the day of year property which provides access to advanced functionality.
Compares this ReadablePartial with another returning true if the chronology, field types and values are equal.
partial | an object to check against |
---|
Get the era property which provides access to advanced functionality.
Constructs a LocalDateTime from a java.util.Calendar
using exactly the same field values.
Each field is queried from the Calendar and assigned to the LocalDateTime. This is useful if you have been using the Calendar as a local date, ignoring the zone.
One advantage of this method is that this method is unaffected if the version of the time zone data differs between the JDK and Joda-Time. That is because the local field values are transferred, calculated using the JDK time zone data and without using the Joda-Time time zone data.
This factory method ignores the type of the calendar and always
creates a LocalDateTime with ISO chronology. It is expected that you
will only pass in instances of GregorianCalendar
however
this is not validated.
calendar | the Calendar to extract fields from |
---|
IllegalArgumentException | if the calendar is null |
---|---|
IllegalArgumentException | if the date is invalid for the ISO chronology |
Constructs a LocalDateTime from a java.util.Date
using exactly the same field values.
Each field is queried from the Date and assigned to the LocalDateTime. This is useful if you have been using the Date as a local date, ignoring the zone.
One advantage of this method is that this method is unaffected if the version of the time zone data differs between the JDK and Joda-Time. That is because the local field values are transferred, calculated using the JDK time zone data and without using the Joda-Time time zone data.
This factory method always creates a LocalDateTime with ISO chronology.
date | the Date to extract fields from |
---|
IllegalArgumentException | if the calendar is null |
---|---|
IllegalArgumentException | if the date is invalid for the ISO chronology |
Get the value of one of the fields of a datetime.
This method gets the value of the specified field. For example:
DateTime dt = new DateTime(); int year = dt.get(DateTimeFieldType.year());
type | a field type, usually obtained from DateTimeFieldType, not null |
---|
IllegalArgumentException | if the field type is null |
---|
Get the year of era field value.
Gets the chronology of the datetime.
Get the day of month field value.
The values for the day of month are defined in DateTimeConstants
.
Get the day of week field value.
The values for the day of week are defined in DateTimeConstants
.
Get the day of year field value.
Get the era field value.
Get the hour of day field value.
Get the millis of day field value.
Get the millis of second field value.
Get the minute of hour field value.
Get the month of year field value.
Get the second of minute field value.
Gets the value of the field at the specifed index.
This method is required to support the ReadablePartial
interface. The supported fields are Year, MonthOfDay, DayOfMonth and MillisOfDay.
index | the index, zero to two |
---|
IndexOutOfBoundsException | if the index is invalid |
---|
Get the week of weekyear field value.
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.
Get the year field value.
Get the year of century field value.
Get the year of era field value.
Get the hour of day field property which provides access to advanced functionality.
Checks if the duration type specified is supported by this local datetime and chronology.
type | a duration type, usually obtained from DurationFieldType |
---|
Checks if the field type specified is supported by this
local datetime and chronology.
This can be used to avoid exceptions in get(DateTimeFieldType)
.
type | a field type, usually obtained from DateTimeFieldType |
---|
Get the millis of day property which provides access to advanced functionality.
Get the millis of second property which provides access to advanced functionality.
Returns a copy of this datetime with the specified period taken 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)
.
period | the period to reduce this instant by |
---|
ArithmeticException | if the result exceeds the internal capacity |
---|
Returns a copy of this datetime with the specified duration taken away.
If the amount is zero or null, then this
is returned.
duration | the duration to reduce this instant by |
---|
ArithmeticException | if the result exceeds the internal capacity |
---|
Returns a copy of this datetime minus the specified number of days.
This LocalDateTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalDateTime subtracted = dt.minusDays(6); LocalDateTime subtracted = dt.minus(Period.days(6)); LocalDateTime subtracted = dt.withFieldAdded(DurationFieldType.days(), -6);
days | the amount of days to subtract, may be negative |
---|
Returns a copy of this datetime minus the specified number of hours.
This LocalDateTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalDateTime subtracted = dt.minusHours(6); LocalDateTime subtracted = dt.minus(Period.hours(6)); LocalDateTime subtracted = dt.withFieldAdded(DurationFieldType.hours(), -6);
hours | the amount of hours to subtract, may be negative |
---|
Returns a copy of this datetime minus the specified number of millis.
This LocalDateTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalDateTime subtracted = dt.minusMillis(6); LocalDateTime subtracted = dt.minus(Period.millis(6)); LocalDateTime subtracted = dt.withFieldAdded(DurationFieldType.millis(), -6);
millis | the amount of millis to subtract, may be negative |
---|
Returns a copy of this datetime minus the specified number of minutes.
This LocalDateTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalDateTime subtracted = dt.minusMinutes(6); LocalDateTime subtracted = dt.minus(Period.minutes(6)); LocalDateTime subtracted = dt.withFieldAdded(DurationFieldType.minutes(), -6);
minutes | the amount of minutes to subtract, may be negative |
---|
Returns a copy of this datetime minus the specified number of months.
This LocalDateTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalDateTime subtracted = dt.minusMonths(6); LocalDateTime subtracted = dt.minus(Period.months(6)); LocalDateTime subtracted = dt.withFieldAdded(DurationFieldType.months(), -6);
months | the amount of months to subtract, may be negative |
---|
Returns a copy of this datetime minus the specified number of seconds.
This LocalDateTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalDateTime subtracted = dt.minusSeconds(6); LocalDateTime subtracted = dt.minus(Period.seconds(6)); LocalDateTime subtracted = dt.withFieldAdded(DurationFieldType.seconds(), -6);
seconds | the amount of seconds to subtract, may be negative |
---|
Returns a copy of this datetime minus the specified number of weeks.
This LocalDateTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalDateTime subtracted = dt.minusWeeks(6); LocalDateTime subtracted = dt.minus(Period.weeks(6)); LocalDateTime subtracted = dt.withFieldAdded(DurationFieldType.weeks(), -6);
weeks | the amount of weeks to subtract, may be negative |
---|
Returns a copy of this datetime minus the specified number of years.
This LocalDateTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalDateTime subtracted = dt.minusYears(6); LocalDateTime subtracted = dt.minus(Period.years(6)); LocalDateTime subtracted = dt.withFieldAdded(DurationFieldType.years(), -6);
years | the amount of years to subtract, may be negative |
---|
Get the minute of hour field property which provides access to advanced functionality.
Get the month of year property which provides access to advanced functionality.
Returns 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)
.
period | the period to add to this one, null means zero |
---|
ArithmeticException | if the result exceeds the internal capacity |
---|
Returns a copy of this datetime with the specified duration added.
If the amount is zero or null, then this
is returned.
duration | the duration to add to this one, null means zero |
---|
ArithmeticException | if the result exceeds the internal capacity |
---|
Returns a copy of this datetime plus the specified number of days.
This LocalDateTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalDateTime added = dt.plusDays(6); LocalDateTime added = dt.plus(Period.days(6)); LocalDateTime added = dt.withFieldAdded(DurationFieldType.days(), 6);
days | the amount of days to add, may be negative |
---|
Returns a copy of this datetime plus the specified number of hours.
This LocalDateTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalDateTime added = dt.plusHours(6); LocalDateTime added = dt.plus(Period.hours(6)); LocalDateTime added = dt.withFieldAdded(DurationFieldType.hours(), 6);
hours | the amount of hours to add, may be negative |
---|
Returns a copy of this datetime plus the specified number of millis.
This LocalDateTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalDateTime added = dt.plusMillis(6); LocalDateTime added = dt.plus(Period.millis(6)); LocalDateTime added = dt.withFieldAdded(DurationFieldType.millis(), 6);
millis | the amount of millis to add, may be negative |
---|
Returns a copy of this datetime plus the specified number of minutes.
This LocalDateTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalDateTime added = dt.plusMinutes(6); LocalDateTime added = dt.plus(Period.minutes(6)); LocalDateTime added = dt.withFieldAdded(DurationFieldType.minutes(), 6);
minutes | the amount of minutes to add, may be negative |
---|
Returns a copy of this datetime plus the specified number of months.
This LocalDateTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalDateTime added = dt.plusMonths(6); LocalDateTime added = dt.plus(Period.months(6)); LocalDateTime added = dt.withFieldAdded(DurationFieldType.months(), 6);
months | the amount of months to add, may be negative |
---|
Returns a copy of this datetime plus the specified number of seconds.
This LocalDateTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalDateTime added = dt.plusSeconds(6); LocalDateTime added = dt.plus(Period.seconds(6)); LocalDateTime added = dt.withFieldAdded(DurationFieldType.seconds(), 6);
seconds | the amount of seconds to add, may be negative |
---|
Returns a copy of this datetime plus the specified number of weeks.
This LocalDateTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalDateTime added = dt.plusWeeks(6); LocalDateTime added = dt.plus(Period.weeks(6)); LocalDateTime added = dt.withFieldAdded(DurationFieldType.weeks(), 6);
weeks | the amount of weeks to add, may be negative |
---|
Returns a copy of this datetime plus the specified number of years.
This LocalDateTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalDateTime added = dt.plusYears(6); LocalDateTime added = dt.plus(Period.years(6)); LocalDateTime added = dt.withFieldAdded(DurationFieldType.years(), 6);
years | the amount of years to add, may be negative |
---|
Gets the property object for the specified type, which contains many useful methods.
fieldType | the field type to get the chronology for |
---|
IllegalArgumentException | if the field is null or unsupported |
---|
Get the second of minute field property which provides access to advanced functionality.
Gets the number of fields in this partial, which is four. The supported fields are Year, MonthOfDay, DayOfMonth and MillisOfDay.
Converts this object to a DateTime using the specified zone.
This method will throw an exception if the datetime that would be created does not exist when the time zone is taken into account.
zone | time zone to apply, or default if null |
---|
Converts this object to a DateTime using the default zone.
This method will throw an exception if the datetime that would be created does not exist when the time zone is taken into account.
this
Converts this object to a LocalDate with the same date and chronology.
Converts this object to a LocalTime with the same time and chronology.
Output the date using the specified format pattern.
pattern | the pattern specification, null means use toString |
---|---|
locale | Locale to use, null means default |
IllegalArgumentException |
---|
Output the date using the specified format pattern.
pattern | the pattern specification, null means use toString |
---|
Output the date time in ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSS).
Get the week of a week based year property which provides access to advanced functionality.
Get the weekyear property which provides access to advanced functionality.
Returns a copy of this datetime with the century of era field updated.
LocalDateTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of century of era changed.
centuryOfEra | the centurey of era to set |
---|
IllegalArgumentException | if the value is invalid |
---|
Returns 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 = dt.monthOfYear().setCopy(6);
year | the new year value |
---|---|
monthOfYear | the new monthOfYear value |
dayOfMonth | the new dayOfMonth value |
IllegalArgumentException | if any value if invalid |
---|
Returns a copy of this datetime with the day of month field updated.
LocalDateTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of day of month changed.
dayOfMonth | the day of month to set |
---|
IllegalArgumentException | if the value is invalid |
---|
Returns a copy of this datetime with the day of week field updated.
LocalDateTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of day of week changed.
dayOfWeek | the day of week to set |
---|
IllegalArgumentException | if the value is invalid |
---|
Returns a copy of this datetime with the day of year field updated.
LocalDateTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of day of year changed.
dayOfYear | the day of year to set |
---|
IllegalArgumentException | if the value is invalid |
---|
Returns a copy of this datetime with the specified duration added.
If the addition is zero, then this
is returned.
durationToAdd | the duration to add to this one, null means zero |
---|---|
scalar | the amount of times to add, such as -1 to subtract once |
ArithmeticException | if the result exceeds the internal capacity |
---|
Returns a copy of this datetime with the era field updated.
LocalDateTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of era changed.
era | the era to set |
---|
IllegalArgumentException | if the value is invalid |
---|
Returns 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:
LocalDateTime updated = dt.withField(DateTimeFieldType.dayOfMonth(), 6); LocalDateTime updated = dt.dayOfMonth().setCopy(6); LocalDateTime updated = dt.property(DateTimeFieldType.dayOfMonth()).setCopy(6);
fieldType | the field type to set, not null |
---|---|
value | the value to set |
IllegalArgumentException | if the value is null or invalid |
---|
Returns 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:
LocalDateTime added = dt.withFieldAdded(DurationFieldType.years(), 6); LocalDateTime added = dt.plusYears(6); LocalDateTime added = dt.plus(Period.years(6));
fieldType | the field type to add to, not null |
---|---|
amount | the amount to add |
IllegalArgumentException | if the value is null or invalid |
---|---|
ArithmeticException | if the result exceeds the internal capacity |
Returns 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.
partial | the partial set of fields to apply to this datetime, null ignored |
---|
IllegalArgumentException | if any value is invalid |
---|
Returns a copy of this datetime with the hour of day field updated.
LocalDateTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of hour of day changed.
hour | the hour of day to set |
---|
IllegalArgumentException | if the value is invalid |
---|
Returns a copy of this datetime with the millis of day field updated.
LocalDateTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of millis of day changed.
millis | the millis of day to set |
---|
IllegalArgumentException | if the value is invalid |
---|
Returns a copy of this datetime with the millis of second field updated.
LocalDateTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of millis of second changed.
millis | the millis of second to set |
---|
IllegalArgumentException | if the value is invalid |
---|
Returns a copy of this datetime with the minute of hour field updated.
LocalDateTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of minute of hour changed.
minute | the minute of hour to set |
---|
IllegalArgumentException | if the value is invalid |
---|
Returns a copy of this datetime with the month of year field updated.
LocalDateTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of month of year changed.
monthOfYear | the month of year to set |
---|
IllegalArgumentException | if the value is invalid |
---|
Returns 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)
.
period | the period to add to this one, null means zero |
---|---|
scalar | the amount of times to add, such as -1 to subtract once |
ArithmeticException | if the result exceeds the internal capacity |
---|
Returns a copy of this datetime with the second of minute field updated.
LocalDateTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of second of minute changed.
second | the second of minute to set |
---|
IllegalArgumentException | if the value is invalid |
---|
Returns 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:
LocalDateTime set = dt.hourOfDay().setCopy(6);
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 any value if invalid |
---|
Returns a copy of this datetime with the week of weekyear field updated.
LocalDateTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of week of weekyear changed.
weekOfWeekyear | the week of weekyear to set |
---|
IllegalArgumentException | if the value is invalid |
---|
Returns a copy of this datetime with the weekyear field updated.
LocalDateTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of weekyear changed.
weekyear | the weekyear to set |
---|
IllegalArgumentException | if the value is invalid |
---|
Returns a copy of this datetime with the year field updated.
LocalDateTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of year changed.
year | the year to set |
---|
IllegalArgumentException | if the value is invalid |
---|
Returns a copy of this datetime with the year of century field updated.
LocalDateTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of year of century changed.
yearOfCentury | the year of century to set |
---|
IllegalArgumentException | if the value is invalid |
---|
Returns a copy of this datetime with the year of era field updated.
LocalDateTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of year of era changed.
yearOfEra | the year of era to set |
---|
IllegalArgumentException | if the value is invalid |
---|
Get the year property which provides access to advanced functionality.
Get the year of century property which provides access to advanced functionality.
Get the year of era property which provides access to advanced functionality.
Gets the field for a specific index in the chronology specified.
This method must not use any instance variables.
index | the index to retrieve |
---|---|
chrono | the chronology to use |
Gets the milliseconds of the datetime instant from the Java epoch of 1970-01-01T00:00:00 (not fixed to any specific time zone).