Temporal adjustInto(Temporal temporal)
描述 (Description)
java.time.OffsetDateTime.adjustInto(Temporal temporal)方法将指定的时态对象调整为与此对象具有相同的日期和时间。
声明 (Declaration)
以下是java.time.OffsetDateTime.adjustInto(Temporal temporal)方法的声明。
public Temporal adjustInto(Temporal temporal)
参数 (Parameters)
temporal - 要调整的目标对象,而不是null。
返回值 (Return Value)
调整后的对象,不为空。
异常 (Exceptions)
DateTimeException - 如果无法进行调整。
ArithmeticException - 如果发生数字溢出。
例子 (Example)
以下示例显示了java.time.OffsetDateTime.adjustInto(Temporal temporal)方法的用法。
package com.iowiki;
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
public class OffsetDateTimeDemo {
public static void main(String[] args) {
ZonedDateTime date = ZonedDateTime.now();
System.out.println(date);
OffsetDateTime date1 = OffsetDateTime.parse("2017-02-03T12:30:30+01:00");
date = (ZonedDateTime)date1.adjustInto(date);
System.out.println(date);
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
2017-03-21T12:07:31.334+05:30[Asia/Calcutta]
2017-02-03T12:30:30+05:30[Asia/Calcutta]