java.time.ZoneOffset.adjustInto() 方法示例



说明

java.time.ZoneOffset.adjustInto(Temporal temporal) 方法调整指定的时间对象以具有这个区域偏移。

声明

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

public Temporal adjustInto(Temporal temporal)

参数

temporal - 要调整的目标对象(不为 null)。

返回值

调整后的对象(不为 null)。

异常

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

  • ArithmeticException - 如果出现数字溢出。

示例

以下示例演示了 java.time.ZoneOffset.adjustInto(Temporal temporal) 方法的使用。

package com.tutorialspoint;

import java.time.ZoneOffset;
import java.time.ZonedDateTime;

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

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

      ZoneOffset zoneOffset = ZoneOffset.of("Z");

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

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

2017-03-30T10:27:47.118+05:30[Asia/Calcutta]
2017-03-30T10:27:47.118+05:30[Asia/Calcutta]
广告
© . All rights reserved.