Home > Java > javaTutorial > body text

What is the purpose of toEpochSecond() method in Java 9?

王林
Release: 2023-09-04 18:09:02
forward
1066 people have browsed it

在Java 9中,toEpochSecond()方法的用途是什么?

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

Grammar

<strong>public long toEpochSecond(LocalTime time, ZoneOffset offset)</strong>
Copy after login

Example

is:

Example

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")));
   }
}
Copy after login

Output

<strong>LocalDate toEpochSecond : 1583496984
LocalTime toEpochSecond : 1583496984</strong>
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template