Java: Get the information of current or given year
Write a Java program to get the information of the current/given year.
Sample format:
Current Year: 2001 Is current year leap year? false Length of the year: 365 days
Sample Solution:
Java Code:
import java.time.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class DateParseFormatExercise25 {
public static void main(String[] args) {
//Current year
Year yr = Year.now();
//given year
//Year yr = Year.of(2001);
System.out.println("\nCurrent Year: " + yr);
boolean isLeap = yr.isLeap(); // false
System.out.println("Is current year leap year? " + isLeap);
int length = yr.length(); // 365
System.out.println("Length of the year: " + length+" days\n");
}
}
Sample Output:
Current Year: 2017 Is current year leap year? false Length of the year: 365 days
N.B.: The result may varry for your system date and time.
Pictorial Presentation:
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Java program to display the current year along with its number of days and leap year status.
- Write a Java program to extract and show details of a user-specified year, including leap year information.
- Write a Java program to compute and display the length of a given year and its first and last days.
- Write a Java program to compare the current year’s length with that of another specified year.
Java Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a Java program to display the dates in the specified formats.
Next: Write a Java program to to get the information of current/given month.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics