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 LocalDateTime
import java.time.*;
public class OfInstantOfLocalDateTime {
public static void main(String args[]) {
// Instantiates a ZoneId and
// Instant
ZoneId 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 ZoneId
LocalDateTime da_ti = LocalDateTime.ofInstant(ins, zo);
// Display da_ti
System.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 根据类名示例化类