java 根据类名示例化类_Java LocalDateTime类| ofInstant()方法与示例
java 根據類名示例化類
LocalDateTime類的Instant()方法 (LocalDateTime Class ofInstant() method)
ofInstant() method is available in java.time package.
ofInstant()方法在java.time包中可用。
ofInstant() method is used to create an instance of LocalDateTime from the given instant and zone.
ofInstant()方法用于從給定的瞬間和區域創建LocalDateTime的實例。
ofInstant() method may throw an exception at the time of representing the object.
ofInstant()方法在表示對象時可能會引發異常。
DateTimeException – This exception may throw when this LocalDateTime value reaches out of the min or max instant.
DateTimeException –當此LocalDateTime值超出最小或最大瞬間時,可能會引發此異常。
ofInstant() method is a static method and it is accessible with the class name and if we try to access these methods with the class object then we will not get an error.
ofInstant()方法是一個靜態方法,可以使用類名進行訪問,如果我們嘗試使用類對象訪問這些方法,則不會出錯。
Syntax:
句法:
public static LocalDateTime ofInstant(Instant ins, ZoneId zo);Parameter(s):
參數:
Instant ins – represents the instant by which we are creating LocalDateTime.
Instant ins –表示我們創建LocalDateTime的瞬間。
ZoneId zo – represents the time zone.
ZoneId zo –代表時區。
Return value:
返回值:
The return type of this method is LocalDateTime, it returns the LocalDateTime that holds the value creates from the given Instant and zone.
該方法的返回類型為LocalDateTime ,它返回LocalDateTime,該LocalDateTime包含從給定的Instant和zone創建的值。
Example:
例:
// Java program to demonstrate the example // of ofInstant(Instant ins, ZoneId zo) method // of LocalDateTimeimport java.time.*;public class OfInstantOfLocalDateTime {public static void main(String args[]) {// Instantiates a ZoneId and// InstantZoneId zo = ZoneId.of("Africa/Accra");Instant ins = Instant.parse("2006-04-03T05:10:15.00Z");// Here, this method creates an instance of // LocalDateTime by using the given// Instant and ZoneIdLocalDateTime da_ti = LocalDateTime.ofInstant(ins, zo);// Display da_tiSystem.out.print("LocalDateTime.ofInstant(ins,zo): ");System.out.println(da_ti);} }Output
輸出量
LocalDateTime.ofInstant(ins,zo): 2006-04-03T05:10:15翻譯自: https://www.includehelp.com/java/localdatetime-ofinstant-method-with-example.aspx
java 根據類名示例化類
總結
以上是生活随笔為你收集整理的java 根据类名示例化类_Java LocalDateTime类| ofInstant()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 面试必备:Spring 面试 63 问!
- 下一篇: 彻夜怒肝!Spring Boot+Sen