![]() |
Calculate the age from a birthdate using the Data/Time API in Java programming, which was introduced in Java 8 to perform this calculation efficiently and accurately. LocalDateLocalDate is a pre-defined class of the Java Date/Time API. It depicts a date without a time zone and keeps the year, month, and day of the month. Syntax: LocalDate localDate = LocalDate.of(year, month, dayOfMonth);
Examples: LocalDate januaryFirst2023 = LocalDate.of(2023, 1, 1); //it takes certain date PeriodPeriod is a class of the Java Date/Time API which is used to depict a period in terms of years, months, and days and to describe the amount of time between two dates in terms of calendar. Syntax: Period periodBetween = Period.between(startDate, endDate);
It takes the starting date, ending date, and return year difference between the two dates. Step-by-Step Implementation
Sample Program: Java
Output
Age: 26 years |
Reffered: https://www.geeksforgeeks.org
Java |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 16 |