ITemporalField.AdjustInto(Object, Int64) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回具有此字段集值的指定临时对象的副本。
[Android.Runtime.Register("adjustInto", "(Ljava/time/temporal/Temporal;J)Ljava/time/temporal/Temporal;", "GetAdjustInto_Ljava_time_temporal_Temporal_JHandler:Java.Time.Temporal.ITemporalFieldInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=26)]
[Java.Interop.JavaTypeParameters(new System.String[] { "R extends java.time.temporal.Temporal" })]
public Java.Lang.Object? AdjustInto(Java.Lang.Object? temporal, long newValue);
[<Android.Runtime.Register("adjustInto", "(Ljava/time/temporal/Temporal;J)Ljava/time/temporal/Temporal;", "GetAdjustInto_Ljava_time_temporal_Temporal_JHandler:Java.Time.Temporal.ITemporalFieldInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=26)>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "R extends java.time.temporal.Temporal" })>]
abstract member AdjustInto : Java.Lang.Object * int64 -> Java.Lang.Object
参数
- temporal
- Object
要调整的临时对象,而不是 null
- newValue
- Int64
字段的新值
返回
调整后的时态对象,而不是 null
- 特性
注解
返回具有此字段集值的指定临时对象的副本。
这将基于具有此字段的值已更改的指定对象返回新的临时对象。 例如,在一个 LocalDate日期上,这可用于设置年份、月或月。 返回的对象具有与指定对象相同的可观察类型。
在某些情况下,更改字段未完全定义。 例如,如果目标对象是表示 1 月 31 日的日期,则将月份更改为 2 月将不清楚。 在这种情况下,实现负责解决结果。 通常,它将选择上一个有效日期,这将是此示例中 2 月的最后一个有效日期。
使用此方法有两种等效的方法。 第一种方法是直接调用此方法。 第二种是使用 Temporal#with(TemporalField, long):
// these two lines are equivalent, but the second approach is recommended
temporal = thisField.adjustInto(temporal);
temporal = temporal.with(thisField);
建议使用第二种方法, with(TemporalField)因为在代码中读取内容要清晰得多。
实现应使用可用 ChronoField字段执行任何查询或计算。 如果不支持该字段, UnsupportedTemporalTypeException 则必须引发该字段。
实现不得更改指定的临时对象。 相反,必须返回原始副本的调整副本。 这为不可变和可变实现提供了等效的安全行为。
Java文档java.time.temporal.TemporalField.adjustInto(R, long)。
本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。