java 根据类名示例化类_Java LocalDateTime类| AdjustInto()方法与示例
java 根據(jù)類名示例化類
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對象調(diào)整為給定的Temporal對象,換句話說,我們可以說調(diào)整后的對象具有與此對象表示的相同日期和時(shí)間。
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()方法是一個非靜態(tài)方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。
adjustInto() method may throw an exception at the time of adjusting Date-Time.
AdjustInto()方法在調(diào)整Date-Time時(shí)可能會引發(fā)異常。
- 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):
參數(shù):
Temporal temp – represents the temporal object to adjust this LocalDateTime.
Temporal temp –表示要調(diào)整此LocalDateTime的時(shí)間對象。
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 ,它將將保存此對象日期時(shí)間調(diào)整后的值的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 根據(jù)類名示例化類
總結(jié)
以上是生活随笔為你收集整理的java 根据类名示例化类_Java LocalDateTime类| AdjustInto()方法与示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python中assert_在Pytho
- 下一篇: mcq 队列_MCQ | 基础知识 免费