当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java java.time.Instant.adjustInto()用法及代码示例



描述

这个java.time.Instant.adjustInto(Temporal temporal)方法调整指定的时间对象以具有这个瞬间。

声明

以下是声明java.time.Instant.adjustInto(Temporal temporal)方法。

public Temporal adjustInto(Temporal temporal)

参数

temporal- 要调整的目标对象,不为空。

返回值

调整后的对象,不为空。

异常

  • DateTimeException− 如果无法进行调整。

  • ArithmeticException- 如果发生数字溢出。

示例

下面的例子展示了 java.time.Instant.adjustInto(Temporal temporal) 方法的用法。

package com.tutorialspoint;

import java.time.Instant;
import java.time.ZonedDateTime;

public class InstantDemo {
   public static void main(String[] args) {

      ZonedDateTime date = ZonedDateTime.now();
      System.out.println(date);  

      Instant instant = Instant.parse("2017-02-03T10:37:30.00Z");

      date = (ZonedDateTime)instant.adjustInto(date);
      System.out.println(date);  
   }
}

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

2017-03-10T11:10:35.454+05:30[Asia/Calcutta]
2017-02-03T16:07:30+05:30[Asia/Calcutta]

相关用法


注:本文由纯净天空筛选整理自 java.time.Instant.adjustInto() Method Example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。