Home | History | Annotate | Download | only in time

Lines Matching refs:time

62 package java.time;
64 import static java.time.LocalTime.NANOS_PER_HOUR;
65 import static java.time.LocalTime.NANOS_PER_MINUTE;
66 import static java.time.LocalTime.NANOS_PER_SECOND;
67 import static java.time.LocalTime.SECONDS_PER_DAY;
68 import static java.time.temporal.ChronoField.NANO_OF_DAY;
69 import static java.time.temporal.ChronoField.OFFSET_SECONDS;
70 import static java.time.temporal.ChronoUnit.NANOS;
78 import java.time.format.DateTimeFormatter;
79 import java.time.format.DateTimeParseException;
80 import java.time.temporal.ChronoField;
81 import java.time.temporal.ChronoUnit;
82 import java.time.temporal.Temporal;
83 import java.time.temporal.TemporalAccessor;
84 import java.time.temporal.TemporalAdjuster;
85 import java.time.temporal.TemporalAmount;
86 import java.time.temporal.TemporalField;
87 import java.time.temporal.TemporalQueries;
88 import java.time.temporal.TemporalQuery;
89 import java.time.temporal.TemporalUnit;
90 import java.time.temporal.UnsupportedTemporalTypeException;
91 import java.time.temporal.ValueRange;
92 import java.time.zone.ZoneRules;
97 * A time with an offset from UTC/Greenwich in the ISO-8601 calendar system,
100 * {@code OffsetTime} is an immutable date-time object that represents a time, often
102 * This class stores all time fields, to a precision of nanoseconds,
117 * This is the time of midnight at the start of the day in the maximum offset
118 * (larger offsets are earlier on the time-line).
125 * This is the time just before midnight at the end of the day in the minimum offset
126 * (larger negative offsets are later on the time-line).
138 * The local date-time.
140 private final LocalTime time;
148 * Obtains the current time from the system clock in the default time-zone.
151 * time-zone to obtain the current time.
152 * The offset will be calculated from the time-zone in the clock.
157 * @return the current time using the system clock and default time-zone, not null
164 * Obtains the current time from the system clock in the specified time-zone.
166 * This will query the {@link Clock#system(ZoneId) system clock} to obtain the current time.
167 * Specifying the time-zone avoids dependence on the default time-zone.
168 * The offset will be calculated from the specified time-zone.
174 * @return the current time using the system clock, not null
181 * Obtains the current time from the specified clock.
183 * This will query the specified clock to obtain the current time.
184 * The offset will be calculated from the time-zone in the clock.
190 * @return the current time, not null
200 * Obtains an instance of {@code OffsetTime} from a local time and an offset.
202 * @param time the local time, not null
204 * @return the offset time, not null
206 public static OffsetTime of(LocalTime time, ZoneOffset offset) {
207 return new OffsetTime(time, offset);
213 * This creates an offset time with the four specified fields.
216 * Non test-code will typically use other methods to create an offset time.
226 * @return the offset time, not null
237 * This creates an offset time with the same instant as that specified.
245 * @param instant the instant to create the time from, not null
246 * @param zone the time-zone, which may be an offset, not null
247 * @return the offset time, not null
256 LocalTime time = LocalTime.ofNanoOfDay(secsOfDay * NANOS_PER_SECOND + instant.getNano());
257 return new OffsetTime(time, offset);
264 * This obtains an offset time based on the specified temporal.
265 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
277 * @return the offset time, not null
285 LocalTime time = LocalTime.from(temporal);
287 return new OffsetTime(time, offset);
298 * The string must represent a valid time and is parsed using
299 * {@link java.time.format.DateTimeFormatter#ISO_OFFSET_TIME}.
302 * @return the parsed local time, not null
312 * The text is parsed using the formatter, returning a time.
316 * @return the parsed offset time, not null
328 * @param time the local time, not null
331 private OffsetTime(LocalTime time, ZoneOffset offset) {
332 this.time = Objects.requireNonNull(time, "time");
337 * Returns a new time based on this one, returning {@code this} where possible.
339 * @param time the time to create with, not null
342 private OffsetTime with(LocalTime time, ZoneOffset offset) {
343 if (this.time == time && this.offset.equals(offset)) {
346 return new OffsetTime(time, offset);
353 * This checks if this time can be queried for the specified field.
386 * @return true if the field is supported on this time, false if not
399 * This checks if the specified unit can be added to, or subtracted from, this offset-time.
437 * This time is used to enhance the accuracy of the returned range.
462 return time.range(field);
468 * Gets the value of the specified field from this time as an {@code int}.
470 * This queries this time for the value of the specified field.
477 * values based on this time, except {@code NANO_OF_DAY} and {@code MICRO_OF_DAY}
500 * Gets the value of the specified field from this time as a {@code long}.
502 * This queries this time for the value of the specified field.
508 * values based on this time.
528 return time.getLong(field);
537 * This is the offset of the local time from UTC/Greenwich.
547 * that the result has the same local time.
551 * For example, if this time represents {@code 10:30+02:00} and the offset specified is
554 * To take into account the difference between the offsets, and adjust the time fields,
560 * @return an {@code OffsetTime} based on this time with the requested offset, not null
563 return offset != null && offset.equals(this.offset) ? this : new OffsetTime(time, offset);
573 * This is useful for finding the local time in a different offset.
574 * For example, if this time represents {@code 10:30+02:00} and the offset specified is
577 * To change the offset without adjusting the local time use {@link #withOffsetSameLocal}.
582 * @return an {@code OffsetTime} based on this time with the requested offset, not null
589 LocalTime adjusted = time.plusSeconds(difference);
595 * Gets the {@code LocalTime} part of this date-time.
598 * nanosecond as this date-time.
600 * @return the time part of this date-time, not null
603 return time;
613 return time.getHour();
622 return time.getMinute();
631 return time.getSecond();
640 return time.getNano();
645 * Returns an adjusted copy of this time.
647 * This returns an {@code OffsetTime}, based on this one, with the time adjusted.
652 * A more complex adjuster might set the time to the last hour of the day.
655 * thus this method can be used to change the time or offset:
657 * result = offsetTime.with(time);
678 return with(time, (ZoneOffset) adjuster);
686 * Returns a copy of this time with the specified field set to a new value.
696 * The {@code OFFSET_SECONDS} field will return a time with the specified offset.
697 * The local time is unaltered. If the new offset value is outside the valid range
725 return with(time, ZoneOffset.ofTotalSeconds(f.checkValidIntValue(newValue)));
727 return with(time.with(field, newValue), offset);
741 * @return an {@code OffsetTime} based on this time with the requested hour, not null
745 return with(time.withHour(hour), offset);
756 * @return an {@code OffsetTime} based on this time with the requested minute, not null
760 return with(time.withMinute(minute), offset);
771 * @return an {@code OffsetTime} based on this time with the requested second, not null
775 return with(time.withSecond(second), offset);
786 * @return an {@code OffsetTime} based on this time with the requested nanosecond, not null
790 return with(time.withNano(nanoOfSecond), offset);
795 * Returns a copy of this {@code OffsetTime} with the time truncated.
797 * Truncation returns a copy of the original time with fields
804 * This includes all supplied time units on {@link ChronoUnit} and
812 * @return an {@code OffsetTime} based on this time with the time truncated, not null
817 return with(time.truncatedTo(unit), offset);
822 * Returns a copy of this time with the specified amount added.
837 * @return an {@code OffsetTime} based on this time with the addition made, not null
847 * Returns a copy of this time with the specified amount added.
866 * @return an {@code OffsetTime} based on this time with the specified amount added, not null
874 return with(time.plus(amountToAdd, unit), offset);
883 * This adds the specified number of hours to this time, returning a new time.
889 * @return an {@code OffsetTime} based on this time with the hours added, not null
892 return with(time.plusHours(hours), offset);
898 * This adds the specified number of minutes to this time, returning a new time.
904 * @return an {@code OffsetTime} based on this time with the minutes added, not null
907 return with(time.plusMinutes(minutes), offset);
913 * This adds the specified number of seconds to this time, returning a new time.
919 * @return an {@code OffsetTime} based on this time with the seconds added, not null
922 return with(time.plusSeconds(seconds), offset);
928 * This adds the specified number of nanoseconds to this time, returning a new time.
934 * @return an {@code OffsetTime} based on this time with the nanoseconds added, not null
937 return with(time.plusNanos(nanos), offset);
942 * Returns a copy of this time with the specified amount subtracted.
957 * @return an {@code OffsetTime} based on this time with the subtraction made, not null
967 * Returns a copy of this time with the specified amount subtracted.
980 * @return an {@code OffsetTime} based on this time with the specified amount subtracted, not null
994 * This subtracts the specified number of hours from this time, returning a new time.
1000 * @return an {@code OffsetTime} based on this time with the hours subtracted, not null
1003 return with(time.minusHours(hours), offset);
1009 * This subtracts the specified number of minutes from this time, returning a new time.
1015 * @return an {@code OffsetTime} based on this time with the minutes subtracted, not null
1018 return with(time.minusMinutes(minutes), offset);
1024 * This subtracts the specified number of seconds from this time, returning a new time.
1030 * @return an {@code OffsetTime} based on this time with the seconds subtracted, not null
1033 return with(time.minusSeconds(seconds), offset);
1039 * This subtracts the specified number of nanoseconds from this time, returning a new time.
1045 * @return an {@code OffsetTime} based on this time with the nanoseconds subtracted, not null
1048 return with(time.minusNanos(nanos), offset);
1053 * Queries this time using the specified query.
1055 * This queries this time using the specified query strategy object.
1078 return (R) time;
1088 * Adjusts the specified temporal object to have the same offset and time
1092 * with the offset and time changed to be the same as this.
1116 .with(NANO_OF_DAY, time.toNanoOfDay())
1121 * Calculates the amount of time until another time in terms of the specified unit.
1123 * This calculates the amount of time between two {@code OffsetTime}
1125 * The start and end points are {@code this} and the specified time.
1133 * end time is normalized to have the same offset as this time.
1162 * @param endExclusive the end time, exclusive, which is converted to an {@code OffsetTime}, not null
1164 * @return the amount of time between this time and the end time
1190 * Formats this time using the specified formatter.
1192 * This time will be passed to the formatter to produce a string.
1195 * @return the formatted time string, not null
1205 * Combines this time with a date to create an {@code OffsetDateTime}.
1207 * This returns an {@code OffsetDateTime} formed from this time and the specified date.
1208 * All possible combinations of date and time are valid.
1211 * @return the offset date-time formed from this time and the specified date, not null
1214 return OffsetDateTime.of(date, time, offset);
1219 * Converts this time to epoch nanos based on 1970-01-01Z.
1224 long nod = time.toNanoOfDay();
1231 * Compares this {@code OffsetTime} to another time.
1233 * The comparison is based first on the UTC equivalent instant, then on the local time.
1245 * Values #2 and #3 represent the same instant on the time-line.
1246 * When two values represent the same instant, the local time is compared
1250 * To compare the underlying local time of two {@code TemporalAccessor} instances,
1253 * @param other the other time to compare to, not null
1260 return time.compareTo(other.time);
1264 compare = time.compareTo(other.time);
1272 * specified time applying both times to a common date.
1275 * only compares the instant of the time. This is equivalent to converting both
1278 * @param other the other time to compare to, not null
1279 * @return true if this is after the instant of the specified time
1287 * specified time applying both times to a common date.
1290 * only compares the instant of the time. This is equivalent to converting both
1293 * @param other the other time to compare to, not null
1294 * @return true if this is before the instant of the specified time
1302 * specified time applying both times to a common date.
1305 * in that it only compares the instant of the time. This is equivalent to converting both
1308 * @param other the other time to compare to, not null
1309 * @return true if this is equal to the instant of the specified time
1317 * Checks if this time is equal to another time.
1319 * The comparison is based on the local-time and the offset.
1320 * To compare for the same instant on the time-line, use {@link #isEqual(OffsetTime)}.
1323 * To compare the underlying local time of two {@code TemporalAccessor} instances,
1327 * @return true if this is equal to the other time
1336 return time.equals(other.time) && offset.equals(other.offset);
1342 * A hash code for this time.
1348 return time.hashCode() ^ offset.hashCode();
1353 * Outputs this time as a {@code String}, such as {@code 10:15:30+01:00}.
1364 * the time where the omitted parts are implied to be zero.
1366 * @return a string representation of this time, not null
1370 return time.toString() + offset.toString();
1376 * <a href="../../serialized-form.html#java.time.Ser">dedicated serialized form</a>.
1380 * // the <a href="../../serialized-form.html#java.time.LocalTime">time</a> excluding the one byte header
1381 * // the <a href="../../serialized-form.html#java.time.ZoneOffset">offset</a> excluding the one byte header
1401 time.writeExternal(out);
1406 LocalTime time = LocalTime.readExternal(in);
1408 return OffsetTime.of(time, offset);