|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.joda.time.base.AbstractPartial org.joda.time.base.BaseLocal org.joda.time.LocalTime
LocalTime is an immutable time class representing a time without a time zone.
LocalTime implements the ReadablePartial
interface.
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()
LocalTime is thread-safe and immutable, provided that the Chronology is as well. All standard Chronology classes supplied are thread-safe and immutable.
Nested Class Summary | |
static class |
LocalTime.Property
LocalTime.Property binds a LocalTime to a DateTimeField allowing powerful datetime functionality to be easily accessed. |
Field Summary | |
static LocalTime |
MIDNIGHT
Constant for midnight. |
Constructor Summary | |
LocalTime()
Constructs an instance set to the current local time evaluated using ISO chronology in the default zone. |
|
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. |
|
LocalTime(int hourOfDay,
int minuteOfHour)
Constructs an instance set to the specified time using ISOChronology . |
|
LocalTime(int hourOfDay,
int minuteOfHour,
int secondOfMinute)
Constructs an instance set to the specified time using ISOChronology . |
|
LocalTime(int hourOfDay,
int minuteOfHour,
int secondOfMinute,
int millisOfSecond)
Constructs an instance set to the specified time using ISOChronology . |
|
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(Object instant)
Constructs an instance from an Object that represents a datetime. |
|
LocalTime(Object instant,
Chronology chronology)
Constructs an instance from an Object that represents a datetime, using the specified chronology. |
|
LocalTime(Object instant,
DateTimeZone zone)
Constructs an instance from an Object that represents a datetime, forcing the time zone to that specified. |
Method Summary | |
int |
compareTo(Object partial)
Compares this partial with another returning an integer indicating the order. |
boolean |
equals(Object partial)
Compares this ReadablePartial with another returning true if the chronology, field types and values are equal. |
static LocalTime |
fromCalendarFields(Calendar calendar)
Constructs a LocalTime from a java.util.Calendar
using exactly the same field values avoiding any time zone effects. |
static LocalTime |
fromDateFields(Date date)
Constructs a LocalTime from a java.util.Date
using exactly the same field values avoiding any time zone effects. |
static LocalTime |
fromMillisOfDay(long millisOfDay)
Constructs a LocalTime from the specified millis of day using the ISO chronology. |
static LocalTime |
fromMillisOfDay(long millisOfDay,
Chronology chrono)
Constructs a LocalTime from the specified millis of day using the specified chronology. |
int |
get(DateTimeFieldType fieldType)
Get the value of one of the fields of time. |
Chronology |
getChronology()
Gets the chronology of the time. |
int |
getHourOfDay()
Get the hour of day field value. |
int |
getMillisOfDay()
Get the millis of day field value. |
int |
getMillisOfSecond()
Get the millis of second field value. |
int |
getMinuteOfHour()
Get the minute of hour field value. |
int |
getSecondOfMinute()
Get the second of minute field value. |
int |
getValue(int index)
Gets the value of the field at the specifed index. |
LocalTime.Property |
hourOfDay()
Get the hour of day field property which provides access to advanced functionality. |
boolean |
isSupported(DateTimeFieldType type)
Checks if the field type specified is supported by this local time and chronology. |
boolean |
isSupported(DurationFieldType type)
Checks if the duration type specified is supported by this local time and chronology. |
LocalTime.Property |
millisOfDay()
Get the millis of day property which provides access to advanced functionality. |
LocalTime.Property |
millisOfSecond()
Get the millis of second property which provides access to advanced functionality. |
LocalTime |
minus(ReadablePeriod period)
Returns a copy of this time with the specified period taken away. |
LocalTime |
minusHours(int hours)
Returns a copy of this time minus the specified number of hours. |
LocalTime |
minusMillis(int millis)
Returns a copy of this time minus the specified number of millis. |
LocalTime |
minusMinutes(int minutes)
Returns a copy of this time minus the specified number of minutes. |
LocalTime |
minusSeconds(int seconds)
Returns a copy of this time minus the specified number of seconds. |
LocalTime.Property |
minuteOfHour()
Get the minute of hour field property which provides access to advanced functionality. |
LocalTime |
plus(ReadablePeriod period)
Returns a copy of this time with the specified period added. |
LocalTime |
plusHours(int hours)
Returns a copy of this time plus the specified number of hours. |
LocalTime |
plusMillis(int millis)
Returns a copy of this time plus the specified number of millis. |
LocalTime |
plusMinutes(int minutes)
Returns a copy of this time plus the specified number of minutes. |
LocalTime |
plusSeconds(int seconds)
Returns a copy of this time plus the specified number of seconds. |
LocalTime.Property |
property(DateTimeFieldType fieldType)
Gets the property object for the specified type, which contains many useful methods. |
LocalTime.Property |
secondOfMinute()
Get the second of minute field property which provides access to advanced functionality. |
int |
size()
Gets the number of fields in this partial, which is four. |
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. |
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. |
String |
toString()
Output the time in ISO8601 format (HH:mm:ss.SSSZZ). |
String |
toString(String pattern)
Output the time using the specified format pattern. |
String |
toString(String pattern,
Locale locale)
Output the time using the specified format pattern. |
LocalTime |
withField(DateTimeFieldType fieldType,
int value)
Returns a copy of this time with the specified field set to a new value. |
LocalTime |
withFieldAdded(DurationFieldType fieldType,
int amount)
Returns a copy of this time with the value of the specified field increased. |
LocalTime |
withFields(ReadablePartial partial)
Returns a copy of this time with the partial set of fields replacing those from this instance. |
LocalTime |
withHourOfDay(int hour)
Returns a copy of this time with the hour of day field updated. |
LocalTime |
withMillisOfDay(int millis)
Returns a copy of this time with the millis of day field updated. |
LocalTime |
withMillisOfSecond(int millis)
Returns a copy of this time with the millis of second field updated. |
LocalTime |
withMinuteOfHour(int minute)
Returns a copy of this time with the minute of hour field updated. |
LocalTime |
withPeriodAdded(ReadablePeriod period,
int scalar)
Returns a copy of this time with the specified period added. |
LocalTime |
withSecondOfMinute(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 class java.lang.Object |
getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.joda.time.ReadablePartial |
getField, getFieldType, hashCode, toDateTime |
Field Detail |
public static final LocalTime MIDNIGHT
Constructor Detail |
public LocalTime()
Once the constructor is completed, the zone is no longer used.
public LocalTime(DateTimeZone 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 zonepublic LocalTime(Chronology 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 zonepublic LocalTime(long instant)
Once the constructor is completed, the zone is no longer used.
instant
- the milliseconds from 1970-01-01T00:00:00Zpublic LocalTime(long instant, DateTimeZone 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:00Zzone
- the time zone, null means default zonepublic LocalTime(long instant, Chronology 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:00Zchronology
- the chronology, null means ISOChronology in default zonepublic LocalTime(Object instant)
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 ISODateTimeFormat.localTimeParser()
.
The default String converter ignores the zone and only parses the field values.
instant
- the datetime object
IllegalArgumentException
- if the instant is invalidpublic LocalTime(Object instant, DateTimeZone zone)
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 ISODateTimeFormat.localTimeParser()
.
The default String converter ignores the zone and only parses the field values.
instant
- the datetime objectzone
- the time zone
IllegalArgumentException
- if the instant is invalidpublic LocalTime(Object instant, Chronology 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 ISODateTimeFormat.localTimeParser()
.
The default String converter ignores the zone and only parses the field values.
instant
- the datetime objectchronology
- the chronology
IllegalArgumentException
- if the instant is invalidpublic LocalTime(int hourOfDay, int minuteOfHour)
ISOChronology
.
hourOfDay
- the hour of the dayminuteOfHour
- the minute of the hourpublic LocalTime(int hourOfDay, int minuteOfHour, int secondOfMinute)
ISOChronology
.
hourOfDay
- the hour of the dayminuteOfHour
- the minute of the hoursecondOfMinute
- the second of the minutepublic LocalTime(int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)
ISOChronology
.
hourOfDay
- the hour of the dayminuteOfHour
- the minute of the hoursecondOfMinute
- the second of the minutemillisOfSecond
- the millisecond of the secondpublic LocalTime(int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond, Chronology chronology)
If the chronology is null, ISOChronology
is used.
hourOfDay
- the hour of the dayminuteOfHour
- the minute of the hoursecondOfMinute
- the second of the minutemillisOfSecond
- the millisecond of the secondchronology
- the chronology, null means ISOChronology in default zoneMethod Detail |
public static LocalTime fromMillisOfDay(long millisOfDay)
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.
millisOfDay
- the number of milliseconds into a day to convertpublic static LocalTime fromMillisOfDay(long millisOfDay, Chronology chrono)
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.
millisOfDay
- the number of milliseconds into a day to convertchrono
- the chronology, null means ISO chronologypublic static LocalTime fromCalendarFields(Calendar calendar)
java.util.Calendar
using exactly the same field values avoiding any time zone effects.
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, ignoing the zone.
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 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 chronologypublic static LocalTime fromDateFields(Date date)
java.util.Date
using exactly the same field values avoiding any time zone effects.
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, ignoing the zone.
This factory method always creates a LocalTime 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 chronologypublic int size()
size
in interface ReadablePartial
public int getValue(int index)
This method is required to support the ReadablePartial
interface. The supported fields are HourOfDay, MinuteOfHour,
SecondOfMinute and MillisOfSecond.
getValue
in interface ReadablePartial
index
- the index, zero to three
IndexOutOfBoundsException
- if the index is invalidpublic int get(DateTimeFieldType fieldType)
This method gets the value of the specified field. For example:
DateTime dt = new DateTime(); int hourOfDay = dt.get(DateTimeFieldType.hourOfDay());
get
in interface ReadablePartial
get
in class AbstractPartial
fieldType
- a field type, usually obtained from DateTimeFieldType, not null
IllegalArgumentException
- if the field type is nullpublic boolean isSupported(DateTimeFieldType type)
get(DateTimeFieldType)
.
isSupported
in interface ReadablePartial
isSupported
in class AbstractPartial
type
- a field type, usually obtained from DateTimeFieldType
public boolean isSupported(DurationFieldType type)
type
- a duration type, usually obtained from DurationFieldType
public Chronology getChronology()
getChronology
in interface ReadablePartial
public boolean equals(Object partial)
equals
in interface ReadablePartial
equals
in class AbstractPartial
partial
- an object to check against
public int compareTo(Object partial)
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.
compareTo
in interface Comparable
compareTo
in class AbstractPartial
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 nullpublic LocalTime withFields(ReadablePartial partial)
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 this
is returned.
partial
- the partial set of fields to apply to this time, null ignored
IllegalArgumentException
- if any value is invalidpublic LocalTime withField(DateTimeFieldType fieldType, int 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 lines are equivalent:
LocalTime updated = dt.withHourOfDay(6); LocalTime updated = dt.withField(DateTimeFieldType.hourOfDay(), 6);
fieldType
- the field type to set, not nullvalue
- the value to set
IllegalArgumentException
- if the value is null or invalidpublic LocalTime withFieldAdded(DurationFieldType fieldType, int amount)
If the addition is zero or the field is null, then this
is 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);
fieldType
- the field type to add to, not nullamount
- the amount to add
IllegalArgumentException
- if the value is null or invalid
ArithmeticException
- if the result exceeds the internal capacitypublic LocalTime withPeriodAdded(ReadablePeriod period, int scalar)
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 plusHours(int)
.
period
- the period to add to this one, null means zeroscalar
- the amount of times to add, such as -1 to subtract once
ArithmeticException
- if the result exceeds the internal capacitypublic LocalTime plus(ReadablePeriod period)
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 plusHours(int)
.
period
- the period to add to this one, null means zero
ArithmeticException
- if the result exceeds the internal capacitypublic LocalTime plusHours(int 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);
hours
- the amount of hours to add, may be negative
public LocalTime plusMinutes(int 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);
minutes
- the amount of minutes to add, may be negative
public LocalTime plusSeconds(int 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);
seconds
- the amount of seconds to add, may be negative
public LocalTime plusMillis(int 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);
millis
- the amount of millis to add, may be negative
public LocalTime minus(ReadablePeriod period)
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 minusHours(int)
.
period
- the period to reduce this instant by
ArithmeticException
- if the result exceeds the internal capacitypublic LocalTime minusHours(int 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);
hours
- the amount of hours to subtract, may be negative
public LocalTime minusMinutes(int 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);
minutes
- the amount of minutes to subtract, may be negative
public LocalTime minusSeconds(int 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);
seconds
- the amount of seconds to subtract, may be negative
public LocalTime minusMillis(int 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);
millis
- the amount of millis to subtract, may be negative
public LocalTime.Property property(DateTimeFieldType fieldType)
fieldType
- the field type to get the chronology for
IllegalArgumentException
- if the field is null or unsupportedpublic int getHourOfDay()
public int getMinuteOfHour()
public int getSecondOfMinute()
public int getMillisOfSecond()
public int getMillisOfDay()
public LocalTime withHourOfDay(int hour)
LocalTime 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 invalidpublic LocalTime withMinuteOfHour(int minute)
LocalTime 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 invalidpublic LocalTime withSecondOfMinute(int second)
LocalTime 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 invalidpublic LocalTime withMillisOfSecond(int millis)
LocalTime 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 invalidpublic LocalTime withMillisOfDay(int millis)
LocalTime 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 invalidpublic LocalTime.Property hourOfDay()
public LocalTime.Property minuteOfHour()
public LocalTime.Property secondOfMinute()
public LocalTime.Property millisOfSecond()
public LocalTime.Property millisOfDay()
public DateTime toDateTimeToday()
public DateTime toDateTimeToday(DateTimeZone zone)
This method uses the chronology from this instance plus the time zone specified.
zone
- the zone to use, null means default
public String toString()
toString
in interface ReadablePartial
public String toString(String pattern)
pattern
- the pattern specification, null means use toString
DateTimeFormat
public String toString(String pattern, Locale locale) throws IllegalArgumentException
pattern
- the pattern specification, null means use toString
locale
- Locale to use, null means default
IllegalArgumentException
DateTimeFormat
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |