In Java 9, the LocalDate class provides the toEpochSecond() method for converting local date to epochsecond. The toEpochSecond() method converts LocalDate to the number of seconds since epoch 1970-01-01T00:00:00Z. LocalDate can be used in conjunction with a given time and time zone offset to calculate the number of seconds since 1970-01-01T00:00:00Z. The Chinese translation of
<strong>public long toEpochSecond(LocalTime time, ZoneOffset offset)</strong>
import java.time.LocalDate; import java.time.LocalTime; import java.time.ZoneOffset; public class ToEpochSecondMethodTest { public static void main(String args[]) { <strong>LocalDate</strong> date = LocalDate.now(); <strong>LocalTime </strong>time = LocalTime.now(); System.out.println("LocalDate toEpochSecond : " + date.<strong>toEpochSecond</strong>(time, <strong>ZoneOffset</strong>.of("Z"))); System.out.println("LocalTime toEpochSecond : " + time.<strong>toEpochSecond</strong>(date, <strong>ZoneOffset</strong>.of("Z"))); } }
<strong>LocalDate toEpochSecond : 1583496984 LocalTime toEpochSecond : 1583496984</strong>
The above is the detailed content of What is the purpose of toEpochSecond() method in Java 9?. For more information, please follow other related articles on the PHP Chinese website!