ChronoLocalDate getLong() method in Java with Examples
The getLong() method of ChronoLocalDate interface in Java gets the era applicable at this date.
Syntax:
public long getLong(TemporalField field)
Parameter: This method accepts a single mandatory parameter field which specifies the field to get and not null.
Return Value: The function returns the value for the field.
Exceptions: The program throws three exceptions which are described as below:
- DateTimeException: thrown if a value for the field cannot be obtained or the value is outside the range of valid values for the field.
- UnsupportedTemporalTypeException: thrown if the field is not supported or the range of values exceeds an long.
- ArithmeticException: thrown if numeric overflow occurs
Below programs illustrate the getLong() method of ChronoLocalDate in Java:
Program 1:
// Program to illustrate the getLong() method import java.util.*; import java.time.*; import java.time.chrono.*; import java.time.temporal.ChronoField; public class GfG { public static void main(String[] args) { // Parses the date ChronoLocalDate dt = LocalDate.parse("2018-11-27"); // Prints the day number System.out.println(dt.getLong( ChronoField.DAY_OF_MONTH)); } } |
27
Program 2:
// Program to illustrate the getLong() method import java.util.*; import java.time.*; import java.time.chrono.*; import java.time.temporal.ChronoField; public class GfG { public static void main(String[] args) { // Parses the date ChronoLocalDate dt = LocalDate.parse("2018-11-27"); // Prints the day number System.out.println(dt.getLong( ChronoField.DAY_OF_YEAR)); } } |
331
Program 3:
// Program to illustrate the getLong() method // Exception Program import java.util.*; import java.time.*; import java.time.chrono.*; import java.time.temporal.ChronoField; public class GfG { public static void main(String[] args) { try { ChronoLocalDate dt = LocalDate.parse("2017-01-32"); System.out.println(dt.getLong( ChronoField.DAY_OF_MONTH)); } catch (Exception e) { System.out.println(e); } } } |
java.time.format.DateTimeParseException: Text '2017-01-32' could not be parsed: Invalid value for DayOfMonth (valid values 1 - 28/31): 32
Recommended Posts:
- ChronoLocalDate until(ChronoLocalDate) Method in Java with Examples
- ByteBuffer getLong() method in Java with Examples
- Instant getLong() method in Java with Examples
- ChronoZonedDateTime getLong() method in Java with Examples
- LocalDate getLong() method in Java with Examples
- Year getLong() method in Java with Examples
- LocalTime getLong() method in Java with Examples
- ChronoLocalDateTime getLong() method in Java with Examples
- MonthDay getLong() method in Java with Examples
- OffsetDateTime getLong() method in Java with examples
- OffsetTime getLong() method in Java with examples
- Field getLong() method in Java with Examples
- ZonedDateTime getLong() method in Java with Examples
- ZoneOffset getLong(TemporalField) method in Java with Examples
- ChronoLocalDate 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.


