日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java 根据类名示例化类_Java即时类| from()方法与示例

發布時間:2023/12/1 java 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 根据类名示例化类_Java即时类| from()方法与示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

java 根據類名示例化類

即時類from()方法 (Instant Class from() method)

  • from() method is available in java.time package.

    from()方法在java.time包中可用。

  • from() method is used to return a copy of the Instant from the given TemporalAccessor object.

    from()方法用于從給定的TemporalAccessor對象返回Instant的副本。

  • from() method is a static method, it is accessible with the class name and if we try to access the method with the class object then we will not get an error.

    from()方法是一個靜態方法,可以使用類名進行訪問,如果嘗試使用類對象訪問該方法,則不會收到錯誤。

  • from() method may throw an exception at the time of returning Instant from the given temp_acc.

    從給定的temp_acc返回Instant時, from()方法可能會引發異常。

    DateTimeException: This exception may throw when the given templ_acc couldn't convert into Instant.

    DateTimeException :當給定的templ_acc無法轉換為Instant時,可能拋出此異常。

Syntax:

句法:

public static Instant from(TemporalAccessor temp_acc);

Parameter(s):

參數:

  • TemporalAccessor temp_acc – represents the temporal accessor to convert to Instant.

    TemporalAccessor temp_acc –表示要轉換為Instant的臨時訪問器。

Return value:

返回值:

The return type of this method is Instant, it returns the Instant that the holds the same value from the given object.

此方法的返回類型為Instant ,它返回Instant,該Instant具有給定對象的相同值。

Example:

例:

// Java program to demonstrate the example // of Instant from(TemporalAccessor temp_acc) // method of Instantimport java.time.*; public class FromOfInstant {public static void main(String args[]) {// Instantiates a OffsetDateTime // and a ZonedDateTime objectOffsetDateTime off_da_time = OffsetDateTime.now();ZonedDateTime zo_da_time = ZonedDateTime.parse("2008-07-06T20:25:30.213+03:00[Africa/Asmara]");// Display off_da_time// and zo_da_timeSystem.out.println("OffsetDateTime off_da_time: ");System.out.println("off_da_time: " + off_da_time);System.out.println();System.out.println("ZonedDateTime zo_da_time: ");System.out.println("zo_da_time: " + zo_da_time);System.out.println();// Here, this method creates an Instant// from the given TemporalAccessor i.e.// here we are creating an Instant(ins)// from the given OffsetDateTime(off_da_time)Instant inst = Instant.from(off_da_time);// Display instSystem.out.println("Instant.from(off_da_time): " + inst);// Here, this method creates an Instant// from the given TemporalAccessor i.e.// here we are creating an Instant(ins)// from the given ZonedDateTime(zo_da_time)inst = Instant.from(zo_da_time);// Display instSystem.out.println("Instant.from(zo_da_time): " + inst);} }

Output

輸出量

OffsetDateTime off_da_time: off_da_time: 2020-05-21T22:00:46.891244ZZonedDateTime zo_da_time: zo_da_time: 2008-07-06T20:25:30.213+03:00[Africa/Asmara]Instant.from(off_da_time): 2020-05-21T22:00:46.891244Z Instant.from(zo_da_time): 2008-07-06T17:25:30.213Z

翻譯自: https://www.includehelp.com/java/instant-from-method-with-example.aspx

java 根據類名示例化類

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的java 根据类名示例化类_Java即时类| from()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。