Java Instant getLong() method7 Jan 2025 | 2 min read The getLong() method of Java Instant class is used to get the value of the specified field from this instant as a long. This returns for the value of the specified field. If it is not possible to return the value because the field is not supported or for some other reason, it throws an exception. SyntaxParametersfield- The value for the field. ReturnThe value of the field. ExceptionsDateTimeException - If a value for the field cannot be obtained or the value is outside the range of valid values for the field. UnsupportedTemporalTypeException - If the field is not supported or the range of values exceeds an int. ArithmeticException - If numeric overflow occurs. Example 1Output: The output will be like this. 0 Example 2Output: The output will be like this. 2018-08-10T06:00:07.269Z NanoOfSecond > 269000000 -- NanoOfDay not supported MicroOfSecond > 269000 -- MicroOfDay not supported MilliOfSecond > 269 -- MilliOfDay not supported -- SecondOfMinute not supported -- SecondOfDay not supported -- MinuteOfHour not supported -- MinuteOfDay not supported -- HourOfAmPm not supported -- ClockHourOfAmPm not supported -- HourOfDay not supported -- ClockHourOfDay not supported -- AmPmOfDay not supported -- DayOfWeek not supported -- AlignedDayOfWeekInMonth not supported -- AlignedDayOfWeekInYear not supported -- DayOfMonth not supported -- DayOfYear not supported -- EpochDay not supported -- AlignedWeekOfMonth not supported -- AlignedWeekOfYear not supported -- MonthOfYear not supported -- ProlepticMonth not supported -- YearOfEra not supported -- Year not supported -- Era not supported InstantSeconds > 1533880807 -- OffsetSeconds not supported Next TopicJava-instant-getepochsecond-method |
The equals () method of Java Instant class is used to check if this instant is equal to the specified instant. Syntax public boolean equals(Object otherInstant) Parameters otherInstant - The other instant, null returns false. Return True, if the other instant is equal to this one, else false. Example 1 import java.time.Instant; public class...
1 min read
The hashCode() method of Java Instant class is used to return a hash code for this instant. Syntax public int hashCode() Parameters No parameters. Return A random integer that is unique for each instance. Example 1 import java.time.Instant; public class InstanthashCodeExample1 { public static void main(String[] args) { ...
1 min read
The getNano() method of Java Instant class is used to get the specific moment on the timeline, from the start of the second. Syntax public int getNano(TemporalField field) Parameters No parameters. Return The nanoseconds within the second, always positive, never exceeds 999,999,999. Example 1 import java.time.Instant; public class InstantgetNanoExample1 { ...
1 min read
The plusNanos() method of Java Instant class is used to return a copy of the instant with the specified duration in nanoseconds added This instance is immutable and unaffected by this method call. Syntax public Instant plusNanos(long NanosToAdd) Parameter nanosToAdd ? It specifies the nanoseconds to add. It can be...
1 min read
The query() method of Java Instant class is used to query the instant using the specified query. This method uses the specified query strategy object. The TemporalQuery object defines the logic to be used to obtain the result. Syntax public <R> R query(TemporalQuery<R> query) Parameters R - As we...
2 min read
The plusSeconds() method of Java Instant class is used to return a copy of the instant with the specified duration in seconds added. This instance is immutable and unaffected by this method call. Syntax public Instant plusSeconds(long secondsToAdd) Parameter secondsToAdd ? It specifies the seconds to add. It can be...
1 min read
The atZone() method of Java Instant class is used to combine the instant with a time-zone to create a ZonedDateTime. Syntax public ZonedDateTime atZone(ZoneId zone) Parameters Zone - The Zone to combine with, not null. Return The Zone date-time formed from this instant and the specified Zone, not null. Exceptions DateTimeException - If...
2 min read
The get() method of Java Instant class is used to get the value of the specified field from this instant as an int. It provides an instant result for the value of the specified field. The returned value will always be within the valid range of...
1 min read
The atOffset() method of Java Instant class is used to combine the instant with an offset to create an OffsetDateTime. Syntax public OffsetDateTime atOffset(ZoneOffset offset) Parameters offset - The offset to combine with, not null. Return The offset date-time formed from this instant and the specified offset, not null. Exceptions DateTimeException - If...
2 min read
The minusMillis () method of Java Instant class is used to return a copy of this instant with the specified duration in milliseconds subtracted. This instance is immutable and unaffected by this method call. Syntax public Instant minusMillis(long millisToSubtract) Parameters millisToSubtract - The milliseconds to subtract, positive or negative. Return An Instant...
1 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India