>  기사  >  Java  >  Java 9에서 toEpochSecond() 메소드의 목적은 무엇입니까?

Java 9에서 toEpochSecond() 메소드의 목적은 무엇입니까?

王林
王林앞으로
2023-09-04 18:09:021022검색

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

Java 9에서 LocalDate 클래스는 현지 날짜를 epoch 초로 변환하는 toEpochSecond() 메서드를 제공합니다. toEpochSecond() 메서드는 LocalDate를 에포크 1970-01-01T00:00:00Z 이후의 초 수로 변환합니다. LocalDate는 주어진 timetimezone offset과 함께 사용하여 1970-01-01T00:00:00Z 이후의 초를 계산할 수 있습니다.

Grammar

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

Example

의 중국어 번역은

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

Output

<strong>LocalDate toEpochSecond : 1583496984
LocalTime toEpochSecond : 1583496984</strong>
입니다.

위 내용은 Java 9에서 toEpochSecond() 메소드의 목적은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 tutorialspoint.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제