< prev index next >

src/java.base/share/classes/java/time/LocalTime.java

Print this page




1471     public int toSecondOfDay() {
1472         int total = hour * SECONDS_PER_HOUR;
1473         total += minute * SECONDS_PER_MINUTE;
1474         total += second;
1475         return total;
1476     }
1477 
1478     /**
1479      * Extracts the time as nanos of day,
1480      * from {@code 0} to {@code 24 * 60 * 60 * 1,000,000,000 - 1}.
1481      *
1482      * @return the nano of day equivalent to this time
1483      */
1484     public long toNanoOfDay() {
1485         long total = hour * NANOS_PER_HOUR;
1486         total += minute * NANOS_PER_MINUTE;
1487         total += second * NANOS_PER_SECOND;
1488         total += nano;
1489         return total;
1490     }















1491 
1492     //-----------------------------------------------------------------------
1493     /**
1494      * Compares this time to another time.
1495      * <p>
1496      * The comparison is based on the time-line position of the local times within a day.
1497      * It is "consistent with equals", as defined by {@link Comparable}.
1498      *
1499      * @param other  the other time to compare to, not null
1500      * @return the comparator value, negative if less, positive if greater
1501      */
1502     @Override
1503     public int compareTo(LocalTime other) {
1504         int cmp = Integer.compare(hour, other.hour);
1505         if (cmp == 0) {
1506             cmp = Integer.compare(minute, other.minute);
1507             if (cmp == 0) {
1508                 cmp = Integer.compare(second, other.second);
1509                 if (cmp == 0) {
1510                     cmp = Integer.compare(nano, other.nano);




1471     public int toSecondOfDay() {
1472         int total = hour * SECONDS_PER_HOUR;
1473         total += minute * SECONDS_PER_MINUTE;
1474         total += second;
1475         return total;
1476     }
1477 
1478     /**
1479      * Extracts the time as nanos of day,
1480      * from {@code 0} to {@code 24 * 60 * 60 * 1,000,000,000 - 1}.
1481      *
1482      * @return the nano of day equivalent to this time
1483      */
1484     public long toNanoOfDay() {
1485         long total = hour * NANOS_PER_HOUR;
1486         total += minute * NANOS_PER_MINUTE;
1487         total += second * NANOS_PER_SECOND;
1488         total += nano;
1489         return total;
1490     }
1491     /**
1492      * Converts this {@code LocalTime} to the number of seconds since the epoch
1493      * of 1970-01-01T00:00:00Z.
1494      * <p>
1495      * This returns the number of seconds from the epoch for this {@link LocalTime}.
1496      *
1497      * @param offset the zone offset, not null
1498      * @return the number of seconds since the epoch of 1970-01-01T00:00:00Z, may be negative
1499      */
1500     public int toEpochSecond(ZoneOffset offset) {
1501         Objects.requireNonNull(offset, "offset");
1502         int secs = toSecondOfDay();
1503         secs -= offset.getTotalSeconds();
1504         return secs;
1505     }
1506 
1507     //-----------------------------------------------------------------------
1508     /**
1509      * Compares this time to another time.
1510      * <p>
1511      * The comparison is based on the time-line position of the local times within a day.
1512      * It is "consistent with equals", as defined by {@link Comparable}.
1513      *
1514      * @param other  the other time to compare to, not null
1515      * @return the comparator value, negative if less, positive if greater
1516      */
1517     @Override
1518     public int compareTo(LocalTime other) {
1519         int cmp = Integer.compare(hour, other.hour);
1520         if (cmp == 0) {
1521             cmp = Integer.compare(minute, other.minute);
1522             if (cmp == 0) {
1523                 cmp = Integer.compare(second, other.second);
1524                 if (cmp == 0) {
1525                     cmp = Integer.compare(nano, other.nano);


< prev index next >