Class OffsetTime
- java.lang.Object
-
- javax.time.calendar.OffsetTime
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<OffsetTime>,Calendrical,CalendricalMatcher,TimeAdjuster,TimeProvider
public final class OffsetTime extends java.lang.Object implements TimeProvider, Calendrical, java.lang.Comparable<OffsetTime>, java.io.Serializable, CalendricalMatcher, TimeAdjuster
A time with a zone offset from UTC in the ISO-8601 calendar system, such as10:15:30+01:00.OffsetTimeis an immutable calendrical that represents a time, often viewed as hour-minute-second-offset. This class stores all time fields, to a precision of nanoseconds, as well as a zone offset. Thus, for example, the value "13:45.30.123456789+02:00" can be stored in aOffsetTime.OffsetTime is immutable and thread-safe.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classOffsetTime.RuleRule implementation.
-
Field Summary
Fields Modifier and Type Field Description private ZoneOffsetoffsetThe zone offset from UTC, never null.private static longserialVersionUIDA serialization identifier for this class.private LocalTimetimeThe local time, never null.
-
Constructor Summary
Constructors Modifier Constructor Description privateOffsetTime(LocalTime time, ZoneOffset offset)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description LocalTimeadjustTime(LocalTime time)Adjusts a time to have the value of the time part of this object.intcompareTo(OffsetTime other)Compares thisOffsetTimeto another time based on the UTC equivalent times then local time.booleanequalInstant(OffsetTime other)Checks if the instant of thisOffsetTimeis equal to that of the specified time applying both times to a common date.booleanequals(java.lang.Object other)Checks if thisOffsetTimeis equal to the specified time.<T> Tget(CalendricalRule<T> rule)Gets the value of the specified calendrical rule.ISOChronologygetChronology()Gets the chronology that this time uses, which is the ISO calendar system.intgetHourOfDay()Gets the hour-of-day field.intgetMinuteOfHour()Gets the minute-of-hour field.intgetNanoOfSecond()Gets the nano-of-second field.ZoneOffsetgetOffset()Gets the zone offset representing how far ahead or behind UTC the time is.intgetSecondOfMinute()Gets the second-of-minute field.inthashCode()A hash code for thisOffsetTime.booleanisAfter(OffsetTime other)Checks if the instant of thisOffsetTimeis after that of the specified time applying both times to a common date.booleanisBefore(OffsetTime other)Checks if the instant of thisOffsetTimeis before that of the specified time applying both times to a common date.booleanmatches(CalendricalMatcher matcher)Checks whether thisOffsetTimematches the specified matcher.booleanmatchesCalendrical(Calendrical calendrical)Checks if the time extracted from the calendrical matches this.OffsetTimeminus(PeriodProvider periodProvider)Returns a copy of thisOffsetTimewith the specified period subtracted.OffsetTimeminus(Duration duration)Returns a copy of thisOffsetTimewith the specified duration subtracted.OffsetTimeminusHours(long hours)Returns a copy of thisOffsetTimewith the specified period in hours subtracted.OffsetTimeminusMinutes(long minutes)Returns a copy of thisOffsetTimewith the specified period in minutes subtracted.OffsetTimeminusNanos(long nanos)Returns a copy of thisOffsetTimewith the specified period in nanoseconds subtracted.OffsetTimeminusSeconds(long seconds)Returns a copy of thisOffsetTimewith the specified period in seconds subtracted.static OffsetTimenow()Obtains the current time from the system clock in the default time-zone.static OffsetTimenow(Clock clock)Obtains the current time from the specified clock.static OffsetTimeof(int hourOfDay, int minuteOfHour, int secondOfMinute, int nanoOfSecond, ZoneOffset offset)Obtains an instance ofOffsetTimefrom an hour, minute, second and nanosecond.static OffsetTimeof(int hourOfDay, int minuteOfHour, int secondOfMinute, ZoneOffset offset)Obtains an instance ofOffsetTimefrom an hour, minute and second.static OffsetTimeof(int hourOfDay, int minuteOfHour, ZoneOffset offset)Obtains an instance ofOffsetTimefrom an hour and minute.static OffsetTimeof(TimeProvider timeProvider, ZoneOffset offset)Obtains an instance ofOffsetTimefrom a time provider.static OffsetTimeofInstant(InstantProvider instantProvider, ZoneOffset offset)Obtains an instance ofOffsetTimefrom anInstantProvider.static OffsetTimeparse(java.lang.String text)Obtains an instance ofOffsetTimefrom a text string such as10:15:30+01:00.static OffsetTimeparse(java.lang.String text, DateTimeFormatter formatter)Obtains an instance ofOffsetTimefrom a text string using a specific formatter.OffsetTimeplus(PeriodProvider periodProvider)Returns a copy of thisOffsetTimewith the specified period added.OffsetTimeplus(Duration duration)Returns a copy of thisOffsetTimewith the specified duration added.OffsetTimeplusHours(long hours)Returns a copy of thisOffsetTimewith the specified period in hours added.OffsetTimeplusMinutes(long minutes)Returns a copy of thisOffsetTimewith the specified period in minutes added.OffsetTimeplusNanos(long nanos)Returns a copy of thisOffsetTimewith the specified period in nanoseconds added.OffsetTimeplusSeconds(long seconds)Returns a copy of thisOffsetTimewith the specified period in seconds added.static CalendricalRule<OffsetTime>rule()Gets the rule forOffsetTime.private longtoEpochNanos()Converts this time to epoch nanos based on 1970-01-01Z.LocalTimetoLocalTime()Converts this time to aLocalTime.java.lang.StringtoString()Outputs this time as aString, such as10:15:30+01:00.java.lang.StringtoString(DateTimeFormatter formatter)Outputs this time as aStringusing the formatter.OffsetTimewith(TimeAdjuster adjuster)Returns a copy of thisOffsetTimewith the time altered using the adjuster.OffsetTimewithHourOfDay(int hourOfDay)Returns a copy of thisOffsetTimewith the hour-of-day value altered.OffsetTimewithMinuteOfHour(int minuteOfHour)Returns a copy of thisOffsetTimewith the minute-of-hour value altered.OffsetTimewithNanoOfSecond(int nanoOfSecond)Returns a copy of thisOffsetTimewith the nano-of-second value altered.OffsetTimewithOffsetSameInstant(ZoneOffset offset)Returns a copy of thisOffsetTimewith the specified offset ensuring that the result is at the same instant on an implied day.OffsetTimewithOffsetSameLocal(ZoneOffset offset)Returns a copy of thisOffsetTimewith the specified offset ensuring that the result has the same local time.OffsetTimewithSecondOfMinute(int secondOfMinute)Returns a copy of thisOffsetTimewith the second-of-minute value altered.OffsetTimewithTime(TimeProvider timeProvider)Returns a copy of thisOffsetTimewith the time altered and the offset retained.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
A serialization identifier for this class.- See Also:
- Constant Field Values
-
time
private final LocalTime time
The local time, never null.
-
offset
private final ZoneOffset offset
The zone offset from UTC, never null.
-
-
Constructor Detail
-
OffsetTime
private OffsetTime(LocalTime time, ZoneOffset offset)
Constructor.- Parameters:
time- the time, validated as not nulloffset- the zone offset, validated as not null
-
-
Method Detail
-
now
public static OffsetTime now()
Obtains the current time from the system clock in the default time-zone.This will query the
system clockin the default time-zone to obtain the current time. The offset will be calculated from the time-zone in the clock.Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.
- Returns:
- the current time using the system clock, never null
-
now
public static OffsetTime now(Clock clock)
Obtains the current time from the specified clock.This will query the specified clock to obtain the current time. The offset will be calculated from the time-zone in the clock.
Using this method allows the use of an alternate clock for testing. The alternate clock may be introduced using
dependency injection.- Parameters:
clock- the clock to use, not null- Returns:
- the current time, never null
-
of
public static OffsetTime of(int hourOfDay, int minuteOfHour, ZoneOffset offset)
Obtains an instance ofOffsetTimefrom an hour and minute.The second and nanosecond fields will be set to zero by this factory method.
- Parameters:
hourOfDay- the hour-of-day to represent, from 0 to 23minuteOfHour- the minute-of-hour to represent, from 0 to 59offset- the zone offset, not null- Returns:
- the offset time, never null
- Throws:
IllegalCalendarFieldValueException- if the value of any field is out of range
-
of
public static OffsetTime of(int hourOfDay, int minuteOfHour, int secondOfMinute, ZoneOffset offset)
Obtains an instance ofOffsetTimefrom an hour, minute and second.The second field will be set to zero by this factory method.
- Parameters:
hourOfDay- the hour-of-day to represent, from 0 to 23minuteOfHour- the minute-of-hour to represent, from 0 to 59secondOfMinute- the second-of-minute to represent, from 0 to 59offset- the zone offset, not null- Returns:
- the offset time, never null
- Throws:
IllegalCalendarFieldValueException- if the value of any field is out of range
-
of
public static OffsetTime of(int hourOfDay, int minuteOfHour, int secondOfMinute, int nanoOfSecond, ZoneOffset offset)
Obtains an instance ofOffsetTimefrom an hour, minute, second and nanosecond.- Parameters:
hourOfDay- the hour-of-day to represent, from 0 to 23minuteOfHour- the minute-of-hour to represent, from 0 to 59secondOfMinute- the second-of-minute to represent, from 0 to 59nanoOfSecond- the nano-of-second to represent, from 0 to 999,999,999offset- the zone offset, not null- Returns:
- the offset time, never null
- Throws:
IllegalCalendarFieldValueException- if the value of any field is out of range
-
of
public static OffsetTime of(TimeProvider timeProvider, ZoneOffset offset)
Obtains an instance ofOffsetTimefrom a time provider.- Parameters:
timeProvider- the time provider to use, not nulloffset- the zone offset, not null- Returns:
- the offset time, never null
-
ofInstant
public static OffsetTime ofInstant(InstantProvider instantProvider, ZoneOffset offset)
Obtains an instance ofOffsetTimefrom anInstantProvider.The date component of the instant is dropped during the conversion. This means that the conversion can never fail due to the instant being out of the valid range of dates.
- Parameters:
instantProvider- the instant to convert, not nulloffset- the zone offset, not null- Returns:
- the offset time, never null
-
parse
public static OffsetTime parse(java.lang.String text)
Obtains an instance ofOffsetTimefrom a text string such as10:15:30+01:00.The following formats are accepted in ASCII:
{Hour}:{Minute}{OffsetID}{Hour}:{Minute}:{Second}{OffsetID}{Hour}:{Minute}:{Second}.{NanosecondFraction}{OffsetID}
The hour has 2 digits with values from 0 to 23. The minute has 2 digits with values from 0 to 59. The second has 2 digits with values from 0 to 59. The nanosecond fraction has from 1 to 9 digits with values from 0 to 999,999,999.
The offset ID is the normalized form as defined in
ZoneOffset.- Parameters:
text- the text to parse such as '10:15:30+01:00', not null- Returns:
- the parsed local time, never null
- Throws:
CalendricalException- if the text cannot be parsed
-
parse
public static OffsetTime parse(java.lang.String text, DateTimeFormatter formatter)
Obtains an instance ofOffsetTimefrom a text string using a specific formatter.The text is parsed using the formatter, returning a time.
- Parameters:
text- the text to parse, not nullformatter- the formatter to use, not null- Returns:
- the parsed offset time, never null
- Throws:
java.lang.UnsupportedOperationException- if the formatter cannot parseCalendricalException- if the text cannot be parsed
-
getChronology
public ISOChronology getChronology()
Gets the chronology that this time uses, which is the ISO calendar system.- Returns:
- the ISO chronology, never null
-
get
public <T> T get(CalendricalRule<T> rule)
Gets the value of the specified calendrical rule.This method queries the value of the specified calendrical rule. If the value cannot be returned for the rule from this time then
nullwill be returned.- Specified by:
getin interfaceCalendrical- Parameters:
rule- the rule to use, not null- Returns:
- the value for the rule, null if the value cannot be returned
-
withTime
public OffsetTime withTime(TimeProvider timeProvider)
Returns a copy of thisOffsetTimewith the time altered and the offset retained.This method returns an object with the same
ZoneOffsetand the specifiedLocalTime. No calculation is needed or performed.- Parameters:
timeProvider- the local time to change to, not null- Returns:
- an
OffsetTimebased on this time with the requested time, never null
-
getOffset
public ZoneOffset getOffset()
Gets the zone offset representing how far ahead or behind UTC the time is.- Returns:
- the zone offset, never null
-
withOffsetSameLocal
public OffsetTime withOffsetSameLocal(ZoneOffset offset)
Returns a copy of thisOffsetTimewith the specified offset ensuring that the result has the same local time.This method returns an object with the same
LocalTimeand the specifiedZoneOffset. No calculation is needed or performed. For example, if this time represents10:30+02:00and the offset specified is+03:00, then this method will return10:30+03:00.To take into account the difference between the offsets, and adjust the time fields, use
withOffsetSameInstant(javax.time.calendar.ZoneOffset).This instance is immutable and unaffected by this method call.
- Parameters:
offset- the zone offset to change to, not null- Returns:
- an
OffsetTimebased on this time with the requested offset, never null
-
withOffsetSameInstant
public OffsetTime withOffsetSameInstant(ZoneOffset offset)
Returns a copy of thisOffsetTimewith the specified offset ensuring that the result is at the same instant on an implied day.This method returns an object with the the specified
ZoneOffsetand aLocalTimeadjusted by the difference between the two offsets. This will result in the old and new objects representing the same instant an an implied day. This is useful for finding the local time in a different offset. For example, if this time represents10:30+02:00and the offset specified is+03:00, then this method will return11:30+03:00.To change the offset without adjusting the local time use
withOffsetSameLocal(javax.time.calendar.ZoneOffset).This instance is immutable and unaffected by this method call.
- Parameters:
offset- the zone offset to change to, not null- Returns:
- an
OffsetTimebased on this time with the requested offset, never null
-
getHourOfDay
public int getHourOfDay()
Gets the hour-of-day field.- Returns:
- the hour-of-day, from 0 to 23
-
getMinuteOfHour
public int getMinuteOfHour()
Gets the minute-of-hour field.- Returns:
- the minute-of-hour, from 0 to 59
-
getSecondOfMinute
public int getSecondOfMinute()
Gets the second-of-minute field.- Returns:
- the second-of-minute, from 0 to 59
-
getNanoOfSecond
public int getNanoOfSecond()
Gets the nano-of-second field.- Returns:
- the nano-of-second, from 0 to 999,999,999
-
with
public OffsetTime with(TimeAdjuster adjuster)
Returns a copy of thisOffsetTimewith the time altered using the adjuster.Adjusters can be used to alter the time in various ways. A simple adjuster might simply set the one of the fields, such as the hour field. A more complex adjuster might set the time to end of the working day.
This instance is immutable and unaffected by this method call.
- Parameters:
adjuster- the adjuster to use, not null- Returns:
- an
OffsetTimebased on this time adjusted as necessary, never null
-
withHourOfDay
public OffsetTime withHourOfDay(int hourOfDay)
Returns a copy of thisOffsetTimewith the hour-of-day value altered.This instance is immutable and unaffected by this method call.
- Parameters:
hourOfDay- the hour-of-day to represent, from 0 to 23- Returns:
- an
OffsetTimebased on this time with the requested hour, never null - Throws:
IllegalCalendarFieldValueException- if the hour value is invalid
-
withMinuteOfHour
public OffsetTime withMinuteOfHour(int minuteOfHour)
Returns a copy of thisOffsetTimewith the minute-of-hour value altered.This instance is immutable and unaffected by this method call.
- Parameters:
minuteOfHour- the minute-of-hour to represent, from 0 to 59- Returns:
- an
OffsetTimebased on this time with the requested minute, never null - Throws:
IllegalCalendarFieldValueException- if the minute value is invalid
-
withSecondOfMinute
public OffsetTime withSecondOfMinute(int secondOfMinute)
Returns a copy of thisOffsetTimewith the second-of-minute value altered.This instance is immutable and unaffected by this method call.
- Parameters:
secondOfMinute- the second-of-minute to represent, from 0 to 59- Returns:
- an
OffsetTimebased on this time with the requested second, never null - Throws:
IllegalCalendarFieldValueException- if the second value is invalid
-
withNanoOfSecond
public OffsetTime withNanoOfSecond(int nanoOfSecond)
Returns a copy of thisOffsetTimewith the nano-of-second value altered.This instance is immutable and unaffected by this method call.
- Parameters:
nanoOfSecond- the nano-of-second to represent, from 0 to 999,999,999- Returns:
- an
OffsetTimebased on this time with the requested nanosecond, never null - Throws:
IllegalCalendarFieldValueException- if the nanos value is invalid
-
plus
public OffsetTime plus(PeriodProvider periodProvider)
Returns a copy of thisOffsetTimewith the specified period added.This adds the specified period to this time, returning a new time. The calculation wraps around midnight and ignores any date-based ISO fields.
The period is interpreted using rules equivalent to
Period.ofTimeFields(PeriodProvider). Those rules ignore any date-based ISO fields, thus adding a date-based period to this time will have no effect.This instance is immutable and unaffected by this method call.
- Parameters:
periodProvider- the period to add, not null- Returns:
- an
OffsetTimebased on this time with the period added, never null - Throws:
CalendricalException- if the specified period cannot be converted to aPeriodjava.lang.ArithmeticException- if the period overflows during conversion to hours/minutes/seconds/nanos
-
plus
public OffsetTime plus(Duration duration)
Returns a copy of thisOffsetTimewith the specified duration added.This adds the specified duration to this time, returning a new time. The calculation wraps around midnight.
The calculation is equivalent to using
plusSeconds(long)andplusNanos(long)on the two parts of the duration.This instance is immutable and unaffected by this method call.
- Parameters:
duration- the duration to add, not null- Returns:
- an
OffsetTimebased on this time with the duration added, never null
-
plusHours
public OffsetTime plusHours(long hours)
Returns a copy of thisOffsetTimewith the specified period in hours added.This adds the specified number of hours to this time, returning a new time. The calculation wraps around midnight.
This instance is immutable and unaffected by this method call.
- Parameters:
hours- the hours to add, may be negative- Returns:
- an
OffsetTimebased on this time with the hours added, never null
-
plusMinutes
public OffsetTime plusMinutes(long minutes)
Returns a copy of thisOffsetTimewith the specified period in minutes added.This adds the specified number of minutes to this time, returning a new time. The calculation wraps around midnight.
This instance is immutable and unaffected by this method call.
- Parameters:
minutes- the minutes to add, may be negative- Returns:
- an
OffsetTimebased on this time with the minutes added, never null
-
plusSeconds
public OffsetTime plusSeconds(long seconds)
Returns a copy of thisOffsetTimewith the specified period in seconds added.This adds the specified number of seconds to this time, returning a new time. The calculation wraps around midnight.
This instance is immutable and unaffected by this method call.
- Parameters:
seconds- the seconds to add, may be negative- Returns:
- an
OffsetTimebased on this time with the seconds added, never null
-
plusNanos
public OffsetTime plusNanos(long nanos)
Returns a copy of thisOffsetTimewith the specified period in nanoseconds added.This adds the specified number of nanoseconds to this time, returning a new time. The calculation wraps around midnight.
This instance is immutable and unaffected by this method call.
- Parameters:
nanos- the nanos to add, may be negative- Returns:
- an
OffsetTimebased on this time with the nanoseconds added, never null
-
minus
public OffsetTime minus(PeriodProvider periodProvider)
Returns a copy of thisOffsetTimewith the specified period subtracted.This subtracts the specified period from this time, returning a new time. The calculation wraps around midnight and ignores any date-based ISO fields.
The period is interpreted using rules equivalent to
Period.ofTimeFields(PeriodProvider). Those rules ignore any date-based ISO fields, thus adding a date-based period to this time will have no effect.This instance is immutable and unaffected by this method call.
- Parameters:
periodProvider- the period to subtract, not null- Returns:
- an
OffsetTimebased on this time with the period subtracted, never null - Throws:
CalendricalException- if the specified period cannot be converted to aPeriodjava.lang.ArithmeticException- if the period overflows during conversion to hours/minutes/seconds/nanos
-
minus
public OffsetTime minus(Duration duration)
Returns a copy of thisOffsetTimewith the specified duration subtracted.This subtracts the specified duration to this time, returning a new time. The calculation wraps around midnight.
The calculation is equivalent to using
minusSeconds(long)andminusNanos(long)on the two parts of the duration.This instance is immutable and unaffected by this method call.
- Parameters:
duration- the duration to subtract, not null- Returns:
- an
OffsetTimebased on this time with the duration subtracted, never null
-
minusHours
public OffsetTime minusHours(long hours)
Returns a copy of thisOffsetTimewith the specified period in hours subtracted.This subtracts the specified number of hours from this time, returning a new time. The calculation wraps around midnight.
This instance is immutable and unaffected by this method call.
- Parameters:
hours- the hours to subtract, may be negative- Returns:
- an
OffsetTimebased on this time with the hours subtracted, never null
-
minusMinutes
public OffsetTime minusMinutes(long minutes)
Returns a copy of thisOffsetTimewith the specified period in minutes subtracted.This subtracts the specified number of minutes from this time, returning a new time. The calculation wraps around midnight.
This instance is immutable and unaffected by this method call.
- Parameters:
minutes- the minutes to subtract, may be negative- Returns:
- an
OffsetTimebased on this time with the minutes subtracted, never null
-
minusSeconds
public OffsetTime minusSeconds(long seconds)
Returns a copy of thisOffsetTimewith the specified period in seconds subtracted.This subtracts the specified number of seconds from this time, returning a new time. The calculation wraps around midnight.
This instance is immutable and unaffected by this method call.
- Parameters:
seconds- the seconds to subtract, may be negative- Returns:
- an
OffsetTimebased on this time with the seconds subtracted, never null
-
minusNanos
public OffsetTime minusNanos(long nanos)
Returns a copy of thisOffsetTimewith the specified period in nanoseconds subtracted.This subtracts the specified number of nanoseconds from this time, returning a new time. The calculation wraps around midnight.
This instance is immutable and unaffected by this method call.
- Parameters:
nanos- the nanos to subtract, may be negative- Returns:
- an
OffsetTimebased on this time with the nanoseconds subtracted, never null
-
matches
public boolean matches(CalendricalMatcher matcher)
Checks whether thisOffsetTimematches the specified matcher.Matchers can be used to query the time. A simple matcher might simply compare one of the fields, such as the hour field. A more complex matcher might check if the time is the last second of the day.
- Parameters:
matcher- the matcher to use, not null- Returns:
- true if this time matches the matcher, false otherwise
-
matchesCalendrical
public boolean matchesCalendrical(Calendrical calendrical)
Checks if the time extracted from the calendrical matches this.This method implements the
CalendricalMatcherinterface. It is intended that applications usematches(javax.time.calendar.CalendricalMatcher)rather than this method.- Specified by:
matchesCalendricalin interfaceCalendricalMatcher- Parameters:
calendrical- the calendrical to match, not null- Returns:
- true if the calendrical matches, false otherwise
-
adjustTime
public LocalTime adjustTime(LocalTime time)
Adjusts a time to have the value of the time part of this object.This method implements the
TimeAdjusterinterface. It is intended that applications usewith(TimeAdjuster)rather than this method.- Specified by:
adjustTimein interfaceTimeAdjuster- Parameters:
time- the time to be adjusted, not null- Returns:
- the adjusted time, never null
-
toLocalTime
public LocalTime toLocalTime()
Converts this time to aLocalTime.- Specified by:
toLocalTimein interfaceTimeProvider- Returns:
- a LocalTime with the same time as this instance, never null
-
toEpochNanos
private long toEpochNanos()
Converts this time to epoch nanos based on 1970-01-01Z.- Returns:
- the epoch nanos value
-
compareTo
public int compareTo(OffsetTime other)
Compares thisOffsetTimeto another time based on the UTC equivalent times then local time.This ordering is consistent with
equals(). For example, the following is the comparator order:10:30+01:0011:00+01:0012:00+02:0011:30+01:0012:00+01:0012:30+01:00
equals().- Specified by:
compareToin interfacejava.lang.Comparable<OffsetTime>- Parameters:
other- the other time to compare to, not null- Returns:
- the comparator value, negative if less, positive if greater
- Throws:
java.lang.NullPointerException- ifotheris null
-
isAfter
public boolean isAfter(OffsetTime other)
Checks if the instant of thisOffsetTimeis after that of the specified time applying both times to a common date.This method differs from the comparison in
compareTo(javax.time.calendar.OffsetTime)in that it only compares the instant of the time. This is equivalent to converting both times to an instant using the same date and comparing the instants.- Parameters:
other- the other time to compare to, not null- Returns:
- true if this is after the instant of the specified time
-
isBefore
public boolean isBefore(OffsetTime other)
Checks if the instant of thisOffsetTimeis before that of the specified time applying both times to a common date.This method differs from the comparison in
compareTo(javax.time.calendar.OffsetTime)in that it only compares the instant of the time. This is equivalent to converting both times to an instant using the same date and comparing the instants.- Parameters:
other- the other time to compare to, not null- Returns:
- true if this is before the instant of the specified time
-
equalInstant
public boolean equalInstant(OffsetTime other)
Checks if the instant of thisOffsetTimeis equal to that of the specified time applying both times to a common date.This method differs from the comparison in
compareTo(javax.time.calendar.OffsetTime)andequals(java.lang.Object)in that it only compares the instant of the time. This is equivalent to converting both times to an instant using the same date and comparing the instants.- Parameters:
other- the other time to compare to, not null- Returns:
- true if this is equal to the instant of the specified time
-
equals
public boolean equals(java.lang.Object other)
Checks if thisOffsetTimeis equal to the specified time.The comparison is based on the time and the offset.
- Overrides:
equalsin classjava.lang.Object- Parameters:
other- the other time to compare to, null returns false- Returns:
- true if this point is equal to the specified time
-
hashCode
public int hashCode()
A hash code for thisOffsetTime.- Overrides:
hashCodein classjava.lang.Object- Returns:
- a suitable hash code
-
toString
public java.lang.String toString()
Outputs this time as aString, such as10:15:30+01:00.The output will be one of the following formats:
HH:mmZZZZHH:mm:ssZZZZHH:mm:ssfnnnZZZZHH:mm:ssfnnnnnnZZZZHH:mm:ssfnnnnnnnnnZZZZ
- Overrides:
toStringin classjava.lang.Object- Returns:
- the formatted time, never null
-
toString
public java.lang.String toString(DateTimeFormatter formatter)
Outputs this time as aStringusing the formatter.- Parameters:
formatter- the formatter to use, not null- Returns:
- the formatted time string, never null
- Throws:
java.lang.UnsupportedOperationException- if the formatter cannot printCalendricalPrintException- if an error occurs during printing
-
rule
public static CalendricalRule<OffsetTime> rule()
Gets the rule forOffsetTime.- Returns:
- the rule for the time, never null
-
-