How to get the current year in Java
In this post we will give you information about How to get the current year in Java. Hear we will give you detail about How to get the current year in JavaAnd how to use it also give you demo for it if it is necessary.
we are going to learn about how to get the current year as an integer in Java.
Getting the current year
To get the current year, we can use the Year.now() method by calling a getValue() on it.
The getValue() method returns the current year in four-digit(2021) format according to the user local time.
Here is an example:
import java.time.Year;public class Main{ public static void main(String[] args) { int year = Year.now().getValue(); System.out.println(year); }}
Output:
2021
Note: This above method is available in Java 8 java.time.Year package.
Hope this code and post will helped you for implement How to get the current year in Java. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs