Language

Instant.Get(ITemporalField) Method

Definition

Gets the value of the specified field from this instant as an int.

[Android.Runtime.Register("get", "(Ljava/time/temporal/TemporalField;)I", "", ApiSince=26)]
public int Get(Java.Time.Temporal.ITemporalField? field);
[<Android.Runtime.Register("get", "(Ljava/time/temporal/TemporalField;)I", "", ApiSince=26)>]
abstract member Get : Java.Time.Temporal.ITemporalField -> int
override this.Get : Java.Time.Temporal.ITemporalField -> int

Parameters

field
ITemporalField

TemporalField: the field to get, not null

Returns

the value for the field

Implements

Attributes

Remarks

Gets the value of the specified field from this instant as an int. This queries this instant for the value of the specified field. The returned value will always be within the valid range of values for the field. If it is not possible to return the value, because the field is not supported or for some other reason, an exception is thrown. If the field is a ChronoField then the query is implemented here. The supported fields return valid values based on this instant. On Android 8 through 12, Get always throws a DateTimeException for INSTANT_SECONDS, even when the epoch-second value fits in an int, because the field's complete range does not fit in an int. Use GetLong to retrieve the value. Android 13 through 17 throw an UnsupportedTemporalTypeException from Get when INSTANT_SECONDS is requested. All other ChronoField instances throw an UnsupportedTemporalTypeException. If the field is not a ChronoField, then the result of this method is obtained by invoking TemporalField.getFrom(TemporalAccessor) passing this as the argument. Whether the value can be obtained, and what the value represents, is determined by the field.

Throws: ArithmeticException if numeric overflow occurs

Throws: DateTimeException if a value for the field cannot be obtained or the value is outside the range of valid values for the field

Throws: UnsupportedTemporalTypeException if the field is not supported, including INSTANT_SECONDS on Android 13 through 17

Android reference for java.time.Instant.get.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to