日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

java 根据类名示例化类_Java LocalDateTime类| AdjustInto()方法与示例

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

java 根據類名示例化類

LocalDateTime類AdjustInto()方法 (LocalDateTime Class adjustInto() method)

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

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

  • adjustInto() method is used to adjust this LocalDateTime object into the given Temporal object or in other words we can say the adjusted object is to have the same date and time represented by this object.

    AdjustInto()方法用于將該LocalDateTime對象調整為給定的Temporal對象,換句話說,我們可以說調整后的對象具有與此對象表示的相同日期和時間。

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

    AdjustInto()方法是一個非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • adjustInto() method may throw an exception at the time of adjusting Date-Time.

    AdjustInto()方法在調整Date-Time時可能會引發異常。

    • DateTimeException – This exception may throw when the given parameter couldn't adjust this LocalDateTime.
    • ArithmeticException – This exception may throw when the calculated result exceeds the length of this Date.

Syntax:

句法:

public Temporal adjustInto(Temporal temp);

Parameter(s):

參數:

  • Temporal temp – represents the temporal object to adjust this LocalDateTime.

    Temporal temp –表示要調整此LocalDateTime的時間對象。

Return value:

返回值:

The return type of this method is Temporal, it returns the Temporal object that holds the value adjusted this object date-time into the given object.

此方法的返回類型為Temporal ,它將將保存此對象日期時間調整后的值的Temporal對象返回給定對象。

Example:

例:

// Java program to demonstrate the example // of adjustInto(Temporal temp) method // of LocalDateTimeimport java.time.*;public class AdjustIntoOfLocalDateTime {public static void main(String args[]) {// Instantiates two LocalDateTime// and a ZonedDateTime objectLocalDateTime da_ti1 = LocalDateTime.parse("2005-10-05T10:10:10");LocalDateTime da_ti2 = LocalDateTime.now();ZonedDateTime zo_da_time = ZonedDateTime.parse("2008-08-08T20:20:20.213+03:00[Africa/Asmara]");// Display da_ti1, da_ti2// and zo_da_timeSystem.out.println("LocalDateTime da_ti1 and da_ti2: ");System.out.println("da_ti1: " + da_ti1);System.out.println("da_ti2: " + da_ti2);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 adjusts this object// into the given object i.e. here we are// adjusting this LocalDateTime(da_ti1)// into the given object ZonedDateTime(zo_da_time)// and the given object is to have same// date and time as this object da_ti1zo_da_time = (ZonedDateTime) da_ti1.adjustInto(zo_da_time);// Display updated zo_da_timeSystem.out.println("da_ti1.adjustInto(zo_da_time): " + zo_da_time);// Here, this method adjusts this object// into the given object i.e. here we are// adjusting this LocalDateTime(da_ti2)// into the given object ZonedDateTime(zo_da_time)// and the given object is to have same// date and time as this object da_ti2zo_da_time = (ZonedDateTime) da_ti2.adjustInto(zo_da_time);// Display updated zo_da_timeSystem.out.println("da_ti2.adjustInto(zo_da_time): " + zo_da_time);} }

Output

輸出量

LocalDateTime da_ti1 and da_ti2: da_ti1: 2005-10-05T10:10:10 da_ti2: 2020-06-04T07:51:48.984048ZonedDateTime zo_da_time: zo_da_time: 2008-08-08T20:20:20.213+03:00[Africa/Asmara]da_ti1.adjustInto(zo_da_time): 2005-10-05T10:10:10+03:00[Africa/Asmara] da_ti2.adjustInto(zo_da_time): 2020-06-04T07:51:48.984048+03:00[Africa/Asmara]

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

java 根據類名示例化類

總結

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

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