OffsetTime getLong() method in Java with examples
The getLong() method of OffsetTime class in Java gets the value of the specified field in the parameter from this time as an long.
Syntax :
public long getLong(TemporalField field)
Parameter: This method accepts a single parameter field which specifies the field to get, not null.
Return Value: It returns the value for the field.
Errors and Exceptions: The program returns three exceptions which are described as below:
- UnsupportedTemporalTypeException: it is thrown if the field is not supported or the range of values exceeds an long.
- DateTimeException: it is thrown if a value for the field cannot be obtained or the value is outside the range of valid values for the field.
- ArithmeticException: it is thrown if numeric overflow occurs
Below programs illustrate the getLong() method:
Program 1 :
// Java program to demonstrate the getLong() method import java.time.OffsetTime; import java.time.temporal.ChronoField; public class GFG { public static void main(String[] args) { // Parses the time OffsetTime time = OffsetTime.parse("11:10:10+11:00"); System.out.println("Gets the long time: " + time.getLong(ChronoField.CLOCK_HOUR_OF_DAY)); } } |
Gets the long time: 11
Program 2 :
// Java program to demonstrate the getLong() method // Exceptions import java.time.OffsetTime; import java.time.temporal.ChronoField; public class GFG { public static void main(String[] args) { try { // Parses the time OffsetTime time = OffsetTime.parse("11:10:10+11:00"); System.out.println("Gets the long time: " + time.getLong(ChronoField.CLOCK_HOUR_OF_DAY)); } catch (Exception e) { System.out.println("Excetpion: " + e); } } } |
Gets the long time: 11
Recommended Posts:
- LocalTime getLong() method in Java with Examples
- ByteBuffer getLong() method in Java with Examples
- MonthDay getLong() method in Java with Examples
- ChronoZonedDateTime getLong() method in Java with Examples
- ChronoLocalDateTime getLong() method in Java with Examples
- Year getLong() method in Java with Examples
- Instant getLong() method in Java with Examples
- ZonedDateTime getLong() method in Java with Examples
- ChronoLocalDate getLong() method in Java with Examples
- Field getLong() method in Java with Examples
- OffsetDateTime getLong() method in Java with examples
- LocalDate getLong() method in Java with Examples
- ZoneOffset getLong(TemporalField) method in Java with Examples
- OffsetTime with() Method in Java with Examples
- OffsetTime from() method in Java with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai



