Class LocalTime
- java.lang.Object
-
- org.joda.time.base.AbstractPartial
-
- org.joda.time.base.BaseLocal
-
- org.joda.time.LocalTime
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<ReadablePartial>,ReadablePartial
public final class LocalTime extends BaseLocal implements ReadablePartial, java.io.Serializable
LocalTime is an immutable time class representing a time without a time zone.LocalTime implements the
ReadablePartialinterface. To do this, the interface methods focus on the key fields - HourOfDay, MinuteOfHour, SecondOfMinute and MillisOfSecond. However, all time fields may in fact be queried.Calculations on LocalTime 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()
- numeric value
- text value
- short text value
- maximum/minimum values
- add/subtract
- set
- rounding
LocalTime is thread-safe and immutable, provided that the Chronology is as well. All standard Chronology classes supplied are thread-safe and immutable.
- Since:
- 1.3
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLocalTime.PropertyLocalTime.Property binds a LocalTime to a DateTimeField allowing powerful datetime functionality to be easily accessed.
-
Constructor Summary
Constructors Constructor Description LocalTime()Constructs an instance set to the current local time evaluated using ISO chronology in the default zone.LocalTime(int hourOfDay, int minuteOfHour)Constructs an instance set to the specified time usingISOChronology.LocalTime(int hourOfDay, int minuteOfHour, int secondOfMinute)Constructs an instance set to the specified time usingISOChronology.LocalTime(int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)Constructs an instance set to the specified time usingISOChronology.LocalTime(int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond, Chronology chronology)Constructs an instance set to the specified time using the specified chronology, whose zone is ignored.LocalTime(long instant)Constructs an instance set to the local time defined by the specified instant evaluated using ISO chronology in the default zone.LocalTime(long instant, Chronology chronology)Constructs an instance set to the local time defined by the specified instant evaluated using the specified chronology.LocalTime(long instant, DateTimeZone zone)Constructs an instance set to the local time defined by the specified instant evaluated using ISO chronology in the specified zone.LocalTime(java.lang.Object instant)Constructs an instance from an Object that represents a datetime.LocalTime(java.lang.Object instant, Chronology chronology)Constructs an instance from an Object that represents a datetime, using the specified chronology.LocalTime(java.lang.Object instant, DateTimeZone zone)Constructs an instance from an Object that represents a datetime, forcing the time zone to that specified.LocalTime(Chronology chronology)Constructs an instance set to the current local time evaluated using specified chronology and zone.LocalTime(DateTimeZone zone)Constructs an instance set to the current local time evaluated using ISO chronology in the specified zone.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(ReadablePartial partial)Compares this partial with another returning an integer indicating the order.booleanequals(java.lang.Object partial)Compares this ReadablePartial with another returning true if the chronology, field types and values are equal.static LocalTimefromCalendarFields(java.util.Calendar calendar)Constructs a LocalTime from ajava.util.Calendarusing exactly the same field values.static LocalTimefromDateFields(java.util.Date date)Constructs a LocalTime from ajava.util.Dateusing exactly the same field values.static LocalTimefromMillisOfDay(long millisOfDay)Constructs a LocalTime from the specified millis of day using the ISO chronology.static LocalTimefromMillisOfDay(long millisOfDay, Chronology chrono)Constructs a LocalTime from the specified millis of day using the specified chronology.intget(DateTimeFieldType fieldType)Get the value of one of the fields of time.ChronologygetChronology()Gets the chronology of the time.intgetHourOfDay()Get the hour of day field value.intgetMillisOfDay()Get the millis of day field value.intgetMillisOfSecond()Get the millis of second field value.intgetMinuteOfHour()Get the minute of hour field value.intgetSecondOfMinute()Get the second of minute field value.intgetValue(int index)Gets the value of the field at the specified index.LocalTime.PropertyhourOfDay()Get the hour of day field property which provides access to advanced functionality.booleanisSupported(DateTimeFieldType type)Checks if the field type specified is supported by this local time and chronology.booleanisSupported(DurationFieldType type)Checks if the duration type specified is supported by this local time and chronology.LocalTime.PropertymillisOfDay()Get the millis of day property which provides access to advanced functionality.LocalTime.PropertymillisOfSecond()Get the millis of second property which provides access to advanced functionality.LocalTimeminus(ReadablePeriod period)Returns a copy of this time with the specified period taken away.LocalTimeminusHours(int hours)Returns a copy of this time minus the specified number of hours.LocalTimeminusMillis(int millis)Returns a copy of this time minus the specified number of millis.LocalTimeminusMinutes(int minutes)Returns a copy of this time minus the specified number of minutes.LocalTimeminusSeconds(int seconds)Returns a copy of this time minus the specified number of seconds.LocalTime.PropertyminuteOfHour()Get the minute of hour field property which provides access to advanced functionality.static LocalTimenow()Obtains aLocalTimeset to the current system millisecond time usingISOChronologyin the default time zone.static LocalTimenow(Chronology chronology)Obtains aLocalTimeset to the current system millisecond time using the specified chronology.static LocalTimenow(DateTimeZone zone)Obtains aLocalTimeset to the current system millisecond time usingISOChronologyin the specified time zone.static LocalTimeparse(java.lang.String str)Parses aLocalTimefrom the specified string.static LocalTimeparse(java.lang.String str, DateTimeFormatter formatter)Parses aLocalTimefrom the specified string using a formatter.LocalTimeplus(ReadablePeriod period)Returns a copy of this time with the specified period added.LocalTimeplusHours(int hours)Returns a copy of this time plus the specified number of hours.LocalTimeplusMillis(int millis)Returns a copy of this time plus the specified number of millis.LocalTimeplusMinutes(int minutes)Returns a copy of this time plus the specified number of minutes.LocalTimeplusSeconds(int seconds)Returns a copy of this time plus the specified number of seconds.LocalTime.Propertyproperty(DateTimeFieldType fieldType)Gets the property object for the specified type, which contains many useful methods.LocalTime.PropertysecondOfMinute()Get the second of minute field property which provides access to advanced functionality.intsize()Gets the number of fields in this partial, which is four.DateTimetoDateTimeToday()Converts this LocalTime to a full datetime using the default time zone setting the time fields from this instance and the date fields from the current date.DateTimetoDateTimeToday(DateTimeZone zone)Converts this LocalTime to a full datetime using the specified time zone setting the time fields from this instance and the date fields from the current time.java.lang.StringtoString()Output the time in ISO8601 format (HH:mm:ss.SSS).java.lang.StringtoString(java.lang.String pattern)Output the time using the specified format pattern.java.lang.StringtoString(java.lang.String pattern, java.util.Locale locale)Output the time using the specified format pattern.LocalTimewithField(DateTimeFieldType fieldType, int value)Returns a copy of this time with the specified field set to a new value.LocalTimewithFieldAdded(DurationFieldType fieldType, int amount)Returns a copy of this time with the value of the specified field increased.LocalTimewithFields(ReadablePartial partial)Returns a copy of this time with the partial set of fields replacing those from this instance.LocalTimewithHourOfDay(int hour)Returns a copy of this time with the hour of day field updated.LocalTimewithMillisOfDay(int millis)Returns a copy of this time with the millis of day field updated.LocalTimewithMillisOfSecond(int millis)Returns a copy of this time with the millis of second field updated.LocalTimewithMinuteOfHour(int minute)Returns a copy of this time with the minute of hour field updated.LocalTimewithPeriodAdded(ReadablePeriod period, int scalar)Returns a copy of this time with the specified period added.LocalTimewithSecondOfMinute(int second)Returns a copy of this time with the second of minute field updated.-
Methods inherited from class org.joda.time.base.AbstractPartial
getField, getFields, getFieldType, getFieldTypes, getValues, hashCode, indexOf, isAfter, isBefore, isEqual, toDateTime, toString
-
Methods inherited from interface org.joda.time.ReadablePartial
getField, getFieldType, hashCode, toDateTime
-
-
-
-
Field Detail
-
MIDNIGHT
public static final LocalTime MIDNIGHT
Constant for midnight.
-
-
Constructor Detail
-
LocalTime
public LocalTime()
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.
- See Also:
now()
-
LocalTime
public LocalTime(DateTimeZone zone)
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.
- Parameters:
zone- the time zone, null means default zone- See Also:
now(DateTimeZone)
-
LocalTime
public LocalTime(Chronology chronology)
Constructs an instance set to the current local time evaluated using specified chronology and zone.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.
- Parameters:
chronology- the chronology, null means ISOChronology in default zone- See Also:
now(Chronology)
-
LocalTime
public LocalTime(long instant)
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.
- Parameters:
instant- the milliseconds from 1970-01-01T00:00:00Z
-
LocalTime
public LocalTime(long instant, DateTimeZone zone)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.
- Parameters:
instant- the milliseconds from 1970-01-01T00:00:00Zzone- the time zone, null means default zone
-
LocalTime
public LocalTime(long instant, Chronology chronology)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.
- Parameters:
instant- the milliseconds from 1970-01-01T00:00:00Zchronology- the chronology, null means ISOChronology in default zone
-
LocalTime
public LocalTime(java.lang.Object instant)
Constructs an instance from an Object that represents a datetime.If the object contains no chronology,
ISOChronologyis 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
ConverterManagerand include ReadablePartial, ReadableInstant, String, Calendar and Date. The String formats are described byISODateTimeFormat.localTimeParser(). The default String converter ignores the zone and only parses the field values.- Parameters:
instant- the datetime object- Throws:
java.lang.IllegalArgumentException- if the instant is invalid
-
LocalTime
public LocalTime(java.lang.Object instant, DateTimeZone zone)Constructs an instance from an Object that represents a datetime, forcing the time zone to that specified.If the object contains no chronology,
ISOChronologyis 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
ConverterManagerand include ReadablePartial, ReadableInstant, String, Calendar and Date. The String formats are described byISODateTimeFormat.localTimeParser(). The default String converter ignores the zone and only parses the field values.- Parameters:
instant- the datetime objectzone- the time zone- Throws:
java.lang.IllegalArgumentException- if the instant is invalid
-
LocalTime
public LocalTime(java.lang.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. Once the constructor is completed, the zone is no longer used.
The recognised object types are defined in
ConverterManagerand include ReadablePartial, ReadableInstant, String, Calendar and Date. The String formats are described byISODateTimeFormat.localTimeParser(). The default String converter ignores the zone and only parses the field values.- Parameters:
instant- the datetime objectchronology- the chronology- Throws:
java.lang.IllegalArgumentException- if the instant is invalid
-
LocalTime
public LocalTime(int hourOfDay, int minuteOfHour)Constructs an instance set to the specified time usingISOChronology.- Parameters:
hourOfDay- the hour of the day, from 0 to 23minuteOfHour- the minute of the hour, from 0 to 59
-
LocalTime
public LocalTime(int hourOfDay, int minuteOfHour, int secondOfMinute)Constructs an instance set to the specified time usingISOChronology.- Parameters:
hourOfDay- the hour of the day, from 0 to 23minuteOfHour- the minute of the hour, from 0 to 59secondOfMinute- the second of the minute, from 0 to 59
-
LocalTime
public LocalTime(int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)Constructs an instance set to the specified time usingISOChronology.- Parameters:
hourOfDay- the hour of the day, from 0 to 23minuteOfHour- the minute of the hour, from 0 to 59secondOfMinute- the second of the minute, from 0 to 59millisOfSecond- the millisecond of the second, from 0 to 999
-
LocalTime
public LocalTime(int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond, Chronology chronology)Constructs an instance set to the specified time using the specified chronology, whose zone is ignored.If the chronology is null,
ISOChronologyis used.- Parameters:
hourOfDay- the hour of the day, valid values defined by the chronologyminuteOfHour- the minute of the hour, valid values defined by the chronologysecondOfMinute- the second of the minute, valid values defined by the chronologymillisOfSecond- the millisecond of the second, valid values defined by the chronologychronology- the chronology, null means ISOChronology in default zone
-
-
Method Detail
-
now
public static LocalTime now()
Obtains aLocalTimeset to the current system millisecond time usingISOChronologyin the default time zone. The resulting object does not use the zone.- Returns:
- the current time, not null
- Since:
- 2.0
-
now
public static LocalTime now(DateTimeZone zone)
Obtains aLocalTimeset to the current system millisecond time usingISOChronologyin the specified time zone. The resulting object does not use the zone.- Parameters:
zone- the time zone, not null- Returns:
- the current time, not null
- Since:
- 2.0
-
now
public static LocalTime now(Chronology chronology)
Obtains aLocalTimeset to the current system millisecond time using the specified chronology. The resulting object does not use the zone.- Parameters:
chronology- the chronology, not null- Returns:
- the current time, not null
- Since:
- 2.0
-
parse
public static LocalTime parse(java.lang.String str)
Parses aLocalTimefrom the specified string.This uses
ISODateTimeFormat.localTimeParser().- Parameters:
str- the string to parse, not null- Since:
- 2.0
-
parse
public static LocalTime parse(java.lang.String str, DateTimeFormatter formatter)
Parses aLocalTimefrom the specified string using a formatter.- Parameters:
str- the string to parse, not nullformatter- the formatter to use, not null- Since:
- 2.0
-
fromMillisOfDay
public static LocalTime fromMillisOfDay(long millisOfDay)
Constructs a LocalTime from the specified millis of day using the ISO chronology.The millisOfDay value may exceed the number of millis in one day, but additional days will be ignored. This method uses the UTC time zone internally.
- Parameters:
millisOfDay- the number of milliseconds into a day to convert
-
fromMillisOfDay
public static LocalTime fromMillisOfDay(long millisOfDay, Chronology chrono)
Constructs a LocalTime from the specified millis of day using the specified chronology.The millisOfDay value may exceed the number of millis in one day, but additional days will be ignored. This method uses the UTC time zone internally.
- Parameters:
millisOfDay- the number of milliseconds into a day to convertchrono- the chronology, null means ISO chronology
-
fromCalendarFields
public static LocalTime fromCalendarFields(java.util.Calendar calendar)
Constructs a LocalTime from ajava.util.Calendarusing exactly the same field values.Each field is queried from the Calendar and assigned to the LocalTime. This is useful if you have been using the Calendar as a local time, 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 LocalTime with ISO chronology. It is expected that you will only pass in instances of
GregorianCalendarhowever this is not validated.- Parameters:
calendar- the Calendar to extract fields from- Returns:
- the created LocalTime
- Throws:
java.lang.IllegalArgumentException- if the calendar is nulljava.lang.IllegalArgumentException- if the date is invalid for the ISO chronology
-
fromDateFields
public static LocalTime fromDateFields(java.util.Date date)
Constructs a LocalTime from ajava.util.Dateusing exactly the same field values.Each field is queried from the Date and assigned to the LocalTime. This is useful if you have been using the Date as a local time, 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 LocalTime with ISO chronology.
- Parameters:
date- the Date to extract fields from- Returns:
- the created LocalTime
- Throws:
java.lang.IllegalArgumentException- if the calendar is nulljava.lang.IllegalArgumentException- if the date is invalid for the ISO chronology
-
size
public int size()
Gets the number of fields in this partial, which is four. The supported fields are HourOfDay, MinuteOfHour, SecondOfMinute and MillisOfSecond.- Specified by:
sizein interfaceReadablePartial- Returns:
- the field count, four
-
getValue
public int getValue(int index)
Gets the value of the field at the specified index.This method is required to support the
ReadablePartialinterface. The supported fields are HourOfDay, MinuteOfHour, SecondOfMinute and MillisOfSecond.- Specified by:
getValuein interfaceReadablePartial- Parameters:
index- the index, zero to three- Returns:
- the value
- Throws:
java.lang.IndexOutOfBoundsException- if the index is invalid
-
get
public int get(DateTimeFieldType fieldType)
Get the value of one of the fields of time.This method gets the value of the specified field. For example:
DateTime dt = new DateTime(); int hourOfDay = dt.get(DateTimeFieldType.hourOfDay());
- Specified by:
getin interfaceReadablePartial- Overrides:
getin classAbstractPartial- Parameters:
fieldType- a field type, usually obtained from DateTimeFieldType, not null- Returns:
- the value of that field
- Throws:
java.lang.IllegalArgumentException- if the field type is null
-
isSupported
public boolean isSupported(DateTimeFieldType type)
Checks if the field type specified is supported by this local time and chronology. This can be used to avoid exceptions inget(DateTimeFieldType).- Specified by:
isSupportedin interfaceReadablePartial- Overrides:
isSupportedin classAbstractPartial- Parameters:
type- a field type, usually obtained from DateTimeFieldType- Returns:
- true if the field type is supported
-
isSupported
public boolean isSupported(DurationFieldType type)
Checks if the duration type specified is supported by this local time and chronology.- Parameters:
type- a duration type, usually obtained from DurationFieldType- Returns:
- true if the field type is supported
-
getChronology
public Chronology getChronology()
Gets the chronology of the time.- Specified by:
getChronologyin interfaceReadablePartial- Returns:
- the Chronology that the time is using
-
equals
public boolean equals(java.lang.Object partial)
Compares this ReadablePartial with another returning true if the chronology, field types and values are equal.- Specified by:
equalsin interfaceReadablePartial- Overrides:
equalsin classAbstractPartial- Parameters:
partial- an object to check against- Returns:
- true if fields and values are equal
-
compareTo
public int compareTo(ReadablePartial partial)
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.
- Specified by:
compareToin interfacejava.lang.Comparable<ReadablePartial>- Overrides:
compareToin classAbstractPartial- Parameters:
partial- an object to check against- Returns:
- negative if this is less, zero if equal, positive if greater
- Throws:
java.lang.ClassCastException- if the partial is the wrong class or if it has field types that don't matchjava.lang.NullPointerException- if the partial is null
-
withFields
public LocalTime withFields(ReadablePartial partial)
Returns a copy of this time with the partial set of fields replacing those from this instance.For example, if the partial contains an hour and minute then those two fields will be changed in the returned instance. Unsupported fields are ignored. If the partial is null, then
thisis returned.- Parameters:
partial- the partial set of fields to apply to this time, null ignored- Returns:
- a copy of this time with a different set of fields
- Throws:
java.lang.IllegalArgumentException- if any value is invalid
-
withField
public LocalTime withField(DateTimeFieldType fieldType, int value)
Returns a copy of this time with the specified field set to a new value.For example, if the field type is
hourOfDaythen the hour of day field would be changed in the returned instance. If the field type is null, thenthisis returned.These lines are equivalent:
LocalTime updated = dt.withHourOfDay(6); LocalTime updated = dt.withField(DateTimeFieldType.hourOfDay(), 6);
- Parameters:
fieldType- the field type to set, not nullvalue- the value to set- Returns:
- a copy of this time with the field set
- Throws:
java.lang.IllegalArgumentException- if the value is null or invalid
-
withFieldAdded
public LocalTime withFieldAdded(DurationFieldType fieldType, int amount)
Returns a copy of this time with the value of the specified field increased.If the addition is zero or the field is null, then
thisis returned.If the addition causes the maximum value of the field to be exceeded, then the value will wrap. Thus 23:59 plus two minutes yields 00:01.
These lines are equivalent:
LocalTime added = dt.plusHours(6); LocalTime added = dt.withFieldAdded(DurationFieldType.hours(), 6);
- Parameters:
fieldType- the field type to add to, not nullamount- the amount to add- Returns:
- a copy of this time with the field updated
- Throws:
java.lang.IllegalArgumentException- if the value is null or invalidjava.lang.ArithmeticException- if the result exceeds the internal capacity
-
withPeriodAdded
public LocalTime withPeriodAdded(ReadablePeriod period, int scalar)
Returns a copy of this time with the specified period added.If the addition is zero, then
thisis 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)orplusHours(int).- Parameters:
period- the period to add to this one, null means zeroscalar- the amount of times to add, such as -1 to subtract once- Returns:
- a copy of this time with the period added
- Throws:
java.lang.ArithmeticException- if the result exceeds the internal capacity
-
plus
public LocalTime plus(ReadablePeriod period)
Returns a copy of this time with the specified period added.If the amount is zero or null, then
thisis returned.This method is typically used to add complex period instances. Adding one field is best achieved using methods like
plusHours(int).- Parameters:
period- the period to add to this one, null means zero- Returns:
- a copy of this time with the period added
- Throws:
java.lang.ArithmeticException- if the result exceeds the internal capacity
-
plusHours
public LocalTime plusHours(int hours)
Returns a copy of this time plus the specified number of hours.This LocalTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalTime added = dt.plusHours(6); LocalTime added = dt.plus(Period.hours(6)); LocalTime added = dt.withFieldAdded(DurationFieldType.hours(), 6);
- Parameters:
hours- the amount of hours to add, may be negative- Returns:
- the new LocalTime plus the increased hours
-
plusMinutes
public LocalTime plusMinutes(int minutes)
Returns a copy of this time plus the specified number of minutes.This LocalTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalTime added = dt.plusMinutes(6); LocalTime added = dt.plus(Period.minutes(6)); LocalTime added = dt.withFieldAdded(DurationFieldType.minutes(), 6);
- Parameters:
minutes- the amount of minutes to add, may be negative- Returns:
- the new LocalTime plus the increased minutes
-
plusSeconds
public LocalTime plusSeconds(int seconds)
Returns a copy of this time plus the specified number of seconds.This LocalTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalTime added = dt.plusSeconds(6); LocalTime added = dt.plus(Period.seconds(6)); LocalTime added = dt.withFieldAdded(DurationFieldType.seconds(), 6);
- Parameters:
seconds- the amount of seconds to add, may be negative- Returns:
- the new LocalTime plus the increased seconds
-
plusMillis
public LocalTime plusMillis(int millis)
Returns a copy of this time plus the specified number of millis.This LocalTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalTime added = dt.plusMillis(6); LocalTime added = dt.plus(Period.millis(6)); LocalTime added = dt.withFieldAdded(DurationFieldType.millis(), 6);
- Parameters:
millis- the amount of millis to add, may be negative- Returns:
- the new LocalTime plus the increased millis
-
minus
public LocalTime minus(ReadablePeriod period)
Returns a copy of this time with the specified period taken away.If the amount is zero or null, then
thisis returned.This method is typically used to subtract complex period instances. Subtracting one field is best achieved using methods like
minusHours(int).- Parameters:
period- the period to reduce this instant by- Returns:
- a copy of this time with the period taken away
- Throws:
java.lang.ArithmeticException- if the result exceeds the internal capacity
-
minusHours
public LocalTime minusHours(int hours)
Returns a copy of this time minus the specified number of hours.This LocalTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalTime subtracted = dt.minusHours(6); LocalTime subtracted = dt.minus(Period.hours(6)); LocalTime subtracted = dt.withFieldAdded(DurationFieldType.hours(), -6);
- Parameters:
hours- the amount of hours to subtract, may be negative- Returns:
- the new LocalTime minus the increased hours
-
minusMinutes
public LocalTime minusMinutes(int minutes)
Returns a copy of this time minus the specified number of minutes.This LocalTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalTime subtracted = dt.minusMinutes(6); LocalTime subtracted = dt.minus(Period.minutes(6)); LocalTime subtracted = dt.withFieldAdded(DurationFieldType.minutes(), -6);
- Parameters:
minutes- the amount of minutes to subtract, may be negative- Returns:
- the new LocalTime minus the increased minutes
-
minusSeconds
public LocalTime minusSeconds(int seconds)
Returns a copy of this time minus the specified number of seconds.This LocalTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalTime subtracted = dt.minusSeconds(6); LocalTime subtracted = dt.minus(Period.seconds(6)); LocalTime subtracted = dt.withFieldAdded(DurationFieldType.seconds(), -6);
- Parameters:
seconds- the amount of seconds to subtract, may be negative- Returns:
- the new LocalTime minus the increased seconds
-
minusMillis
public LocalTime minusMillis(int millis)
Returns a copy of this time minus the specified number of millis.This LocalTime instance is immutable and unaffected by this method call.
The following three lines are identical in effect:
LocalTime subtracted = dt.minusMillis(6); LocalTime subtracted = dt.minus(Period.millis(6)); LocalTime subtracted = dt.withFieldAdded(DurationFieldType.millis(), -6);
- Parameters:
millis- the amount of millis to subtract, may be negative- Returns:
- the new LocalTime minus the increased millis
-
property
public LocalTime.Property property(DateTimeFieldType fieldType)
Gets the property object for the specified type, which contains many useful methods.- Parameters:
fieldType- the field type to get the chronology for- Returns:
- the property object
- Throws:
java.lang.IllegalArgumentException- if the field is null or unsupported
-
getHourOfDay
public int getHourOfDay()
Get the hour of day field value.- Returns:
- the hour of day
-
getMinuteOfHour
public int getMinuteOfHour()
Get the minute of hour field value.- Returns:
- the minute of hour
-
getSecondOfMinute
public int getSecondOfMinute()
Get the second of minute field value.- Returns:
- the second of minute
-
getMillisOfSecond
public int getMillisOfSecond()
Get the millis of second field value.- Returns:
- the millis of second
-
getMillisOfDay
public int getMillisOfDay()
Get the millis of day field value.- Returns:
- the millis of day
-
withHourOfDay
public LocalTime withHourOfDay(int hour)
Returns a copy of this time with the hour of day field updated.LocalTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of hour of day changed.
- Parameters:
hour- the hour of day to set- Returns:
- a copy of this object with the field set
- Throws:
java.lang.IllegalArgumentException- if the value is invalid
-
withMinuteOfHour
public LocalTime withMinuteOfHour(int minute)
Returns a copy of this time with the minute of hour field updated.LocalTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of minute of hour changed.
- Parameters:
minute- the minute of hour to set- Returns:
- a copy of this object with the field set
- Throws:
java.lang.IllegalArgumentException- if the value is invalid
-
withSecondOfMinute
public LocalTime withSecondOfMinute(int second)
Returns a copy of this time with the second of minute field updated.LocalTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of second of minute changed.
- Parameters:
second- the second of minute to set- Returns:
- a copy of this object with the field set
- Throws:
java.lang.IllegalArgumentException- if the value is invalid
-
withMillisOfSecond
public LocalTime withMillisOfSecond(int millis)
Returns a copy of this time with the millis of second field updated.LocalTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of millis of second changed.
- Parameters:
millis- the millis of second to set- Returns:
- a copy of this object with the field set
- Throws:
java.lang.IllegalArgumentException- if the value is invalid
-
withMillisOfDay
public LocalTime withMillisOfDay(int millis)
Returns a copy of this time with the millis of day field updated.LocalTime is immutable, so there are no set methods. Instead, this method returns a new instance with the value of millis of day changed.
- Parameters:
millis- the millis of day to set- Returns:
- a copy of this object with the field set
- Throws:
java.lang.IllegalArgumentException- if the value is invalid
-
hourOfDay
public LocalTime.Property hourOfDay()
Get the hour of day field property which provides access to advanced functionality.- Returns:
- the hour of day property
-
minuteOfHour
public LocalTime.Property minuteOfHour()
Get the minute of hour field property which provides access to advanced functionality.- Returns:
- the minute of hour property
-
secondOfMinute
public LocalTime.Property secondOfMinute()
Get the second of minute field property which provides access to advanced functionality.- Returns:
- the second of minute property
-
millisOfSecond
public LocalTime.Property millisOfSecond()
Get the millis of second property which provides access to advanced functionality.- Returns:
- the millis of second property
-
millisOfDay
public LocalTime.Property millisOfDay()
Get the millis of day property which provides access to advanced functionality.- Returns:
- the millis of day property
-
toDateTimeToday
public DateTime toDateTimeToday()
Converts this LocalTime to a full datetime using the default time zone setting the time fields from this instance and the date fields from the current date.- Returns:
- this time as a datetime using today's date
-
toDateTimeToday
public DateTime toDateTimeToday(DateTimeZone zone)
Converts this LocalTime to a full datetime using the specified time zone setting the time fields from this instance and the date fields from the current time.This method uses the chronology from this instance plus the time zone specified.
- Parameters:
zone- the zone to use, null means default- Returns:
- this time as a datetime using today's date
-
toString
public java.lang.String toString()
Output the time in ISO8601 format (HH:mm:ss.SSS).- Specified by:
toStringin interfaceReadablePartial- Overrides:
toStringin classjava.lang.Object- Returns:
- ISO8601 time formatted string.
-
toString
public java.lang.String toString(java.lang.String pattern)
Output the time using the specified format pattern.- Parameters:
pattern- the pattern specification, null means usetoString- See Also:
DateTimeFormat
-
toString
public java.lang.String toString(java.lang.String pattern, java.util.Locale locale) throws java.lang.IllegalArgumentExceptionOutput the time using the specified format pattern.- Parameters:
pattern- the pattern specification, null means usetoStringlocale- Locale to use, null means default- Throws:
java.lang.IllegalArgumentException- See Also:
DateTimeFormat
-
-