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