> Java > java지도 시간 > 본문

Java 9에서 ofInstant() 메소드의 중요성은 무엇입니까?

WBOY
풀어 주다: 2023-09-13 13:57:03
앞으로
1057명이 탐색했습니다.

在Java 9中,ofInstant()方法的重要性是什么?

Java 9에서는 변환을 위해 ofInstant() 메서드가 도입되었습니다. LocalDate, LocalTimeLocalDateTime 클래스의 정적 메서드입니다. 이 메소드는 java.time.Instant 객체를 LocalDate로 변환하며, java.time.ZoneId 형식의 시간대가 필요합니다.

구문

<strong>public static LocalTime ofInstant(Instant instant, ZoneId zone)
public static LocalDate ofInstant(Instant instant, ZoneId zone)
public static LocalDateTime ofInstant(Instant instant, ZoneId zone)</strong>
로그인 후 복사

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.LocalDateTime;
import java.time.Instant;
import java.time.ZoneId;

public class OfInstantMethodTest {
   public static void main(String args[]) {
      <strong>Instant </strong>instant = Instant.<strong>parse</strong>("2020-02-05T02:35:15.245Z");
      System.out.println("Instant: " + instant);

      <strong>LocalDate </strong>ld = LocalDate.<strong>ofInstant</strong>(instant, <strong>ZoneId</strong>.of("Asia/Kolkata"));
      System.out.println("LocalDate: " + ld);

      <strong>LocalTime </strong>lt = LocalTime.<strong>ofInstant</strong>(instant, <strong>ZoneId</strong>.of("Asia/Kolkata"));
      System.out.println("LocalTime: " + lt);

      <strong>LocalDateTime </strong>ldt = LocalDateTime.<strong>ofInstant</strong>(instant, <strong>ZoneId</strong>.of("Asia/Kolkata"));
      System.out.println("LocalDateTime: " + ldt);
   }
}
로그인 후 복사

출력

<strong>Instant: 2020-02-05T02:35:15.245Z
LocalDate: 2020-02-05
LocalTime: 08:05:15.245
LocalDateTime: 2020-02-05T08:05:15.245</strong>
로그인 후 복사

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

원천:tutorialspoint.com
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!