目录

static OffsetDateTime from(TemporalAccessor temporal)

描述 (Description)

java.time.OffsetDateTime.from(TemporalAccessor temporal)方法从时态对象获取OffsetDateTime的实例。

声明 (Declaration)

以下是java.time.OffsetDateTime.from(TemporalAccessor temporal)方法的声明。

public static OffsetDateTime from(TemporalAccessor temporal)

参数 (Parameters)

temporal - 要转换的时间对象,而不是null。

返回值 (Return Value)

本地日期,不为空。

异常 (Exceptions)

DateTimeException - 如果无法转换为OffsetDateTime。

例子 (Example)

以下示例显示了java.time.OffsetDateTime.from(TemporalAccessor temporal)方法的用法。

package com.iowiki;
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
public class OffsetDateTimeDemo {
   public static void main(String[] args) {
      OffsetDateTime date = OffsetDateTime.from(ZonedDateTime.now());
      System.out.println(date);  
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

2017-03-21T12:15:35.619+05:30
↑回到顶部↑
WIKI教程 @2018