Instant toInstant()
描述 (Description)
java.time.OffsetDateTime.toInstant()方法将此日期时间转换为Instant。
声明 (Declaration)
以下是java.time.OffsetDateTime.toInstant()方法的声明。
public Instant toInstant()
返回值 (Return Value)
表示同一时刻的Instant,而不是null。
例子 (Example)
以下示例显示了java.time.OffsetDateTime.toInstant()方法的用法。
package com.iowiki;
import java.time.OffsetDateTime;
public class OffsetDateTimeDemo {
public static void main(String[] args) {
OffsetDateTime date = OffsetDateTime.now();
System.out.println(date.toInstant());
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
2017-03-21T08:45:08.755Z