java.time.ZonedDateTime.from() 方法

描述

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


声明

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

public static ZonedDateTime from(TemporalAccessor temporal)

参数

temporal − 要转换的时间对象,不为空。


返回值

本地日期,不为空。


异常

DateTimeException − 如果无法转换为 ZonedDateTime。


示例

下面的例子展示了 java.time.ZonedDateTime.from(TemporalAccessor temporal) 方法的使用。

package com.tutorialspoint;

import java.time.ZonedDateTime;

public class ZonedDateTimeDemo {
   public static void main(String[] args) {
 
      ZonedDateTime date = ZonedDateTime.from(ZonedDateTime.now());
      System.out.println(date);  
   }
}

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

2017-03-28T12:25:38.492+05:30[Asia/Calcutta]