static ZonedDateTime ofInstant(Instant instant, ZoneId zone)
描述 (Description)
java.time.ZonedDateTime.ofInstant(Instant instant, ZoneId zone)方法从Instant和区域ID获取ZonedDateTime的实例。
声明 (Declaration)
以下是java.time.ZonedDateTime.ofInstant(Instant instant, ZoneId zone)方法的声明。
public static ZonedDateTime ofInstant(Instant instant, ZoneId zone)
参数 (Parameters)
instant - 创建日期时间的瞬间,而不是空。
zone - 时区,可以是偏移量,而不是null。
返回值 (Return Value)
本地日期,不为空。
异常 (Exceptions)
DateTimeException - 如果结果超出支持的范围。
例子 (Example)
以下示例显示了java.time.ZonedDateTime.ofInstant(即时即时,ZoneId区域)方法的用法。
package com.iowiki;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.ZoneId;
public class ZonedDateTimeDemo {
public static void main(String[] args) {
ZonedDateTime date = ZonedDateTime.ofInstant(Instant.now(), ZoneId.systemDefault() );
System.out.println(date);
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
2017-03-28T13:58:14.543+05:30[Asia/Calcutta]