java.time.ZonedDateTime.ofInstant(Instant instant, ZoneId zone)方法从Instant和区域ID获取ZonedDateTime的实例。
声明
以下是java.time.ZonedDateTime.ofInstant(Instant instant, ZoneId zone)方法的声明。
public static ZonedDateTime ofInstant(Instant instant, ZoneId zone)
参数
- instant- 创建日期时间的瞬间,而不是- null。
- zone- 时区可以是偏移量,而不是- null。
返回值
本地日期,不为null。
例外
- DateTimeException- 如果结果超出支持的范围。
示例
以下示例显示了java.time.ZonedDateTime.ofInstant(Instant instant, ZoneId zone)方法的用法。
package com.zaixian;
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]
						上一篇:
								java.time.ZonedDateTime类
												下一篇:
								java.time.ZoneId类
												
						
						
					
					
					