< prev index next >

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

Print this page

        

@@ -1861,10 +1861,26 @@
             }
         }
         return total - DAYS_0000_TO_1970;
     }
 
+    /**
+     * Converts this {@code LocalDate} to the number of seconds since the epoch
+     * of 1970-01-01T00:00:00Z.
+     * <p>
+     * This returns the number of seconds from the epoch for this {@link LocalDate}.
+     *
+     * @param offset the zone offset, not null
+     * @return the number of seconds since the epoch of 1970-01-01T00:00:00Z, may be negative
+     */
+    public long toEpochSecond(ZoneOffset offset) {
+        Objects.requireNonNull(offset, "offset");
+        long secs = toEpochDay() * SECONDS_PER_DAY;
+        secs -= offset.getTotalSeconds();
+        return secs;
+    }
+
     //-----------------------------------------------------------------------
     /**
      * Compares this date to another date.
      * <p>
      * The comparison is primarily based on the date, from earliest to latest.
< prev index next >