@FunctionalInterface public interface TemporalAdjuster
算是对时空对象的关键工具。他们的存在使得调整的过程中,允许不同的方法,根据策略设计模式。例子可能是一个调节器,设置日期避免周末,或一个设置日期到月的最后一天。
有使用TemporalAdjuster
两等效方法。首先是直接调用这个接口的方法。二是用Temporal.with(TemporalAdjuster)
:
这两条线是等价的,但第二种方法是建议时间= thisadjuster adjustinto(时间);时间=(thisadjuster)与时间;建议使用第二种方法,
with(TemporalAdjuster)
,因为它是一个更清晰的读码。
的TemporalAdjusters
类包含一组标准的调节器,可以作为静态方法。这些措施包括:
TemporalAdjusters
Modifier and Type | Method and Description |
---|---|
Temporal |
adjustInto(Temporal temporal)
调整指定的时间对象。
|
Temporal adjustInto(Temporal temporal)
这将调整指定的时间对象,使用封装在实现类中的逻辑。例子可能是一个调节器,设置日期避免周末,或一个设置日期到月的最后一天。
使用这种方法有两个等效的方法。首先是直接调用这个方法。二是用Temporal.with(TemporalAdjuster)
:
这两条线是等价的,但第二种方法是建议时间= thisadjuster adjustinto(时间);时间=(thisadjuster)与时间;建议使用第二种方法,
with(TemporalAdjuster)
,因为它是一个更清晰的读码。
Temporal
方法查询对象进行调整。返回的对象必须具有相同的观察到的类型作为输入对象
输入对象不能被更改。相反,必须返回原始的调整副本。这提供了等效,为不变的和可变的时空对象的安全行为。
输入的时间对象可能是在其他的日历系统中。实现可以选择的文件与其他日历系统兼容,或拒绝非异时空对象的querying the chronology
。
这种方法可以从多个线程中调用。当调用时它必须是线程安全的。
temporal
-调整时间的对象,不为空
DateTimeException
如果无法适应
ArithmeticException
如果数值溢出时
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.