- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to get current date, year and month
Import the following package for using Calendar class,
import java.util.Calendar;
Create a calendar object as shown below −
Calendar cal = Calendar.getInstance();
Let us now get the current date, year and month.
cal.get(Calendar.YEAR) cal.get(Calendar.MONTH) + 1 cal.get(Calendar.DATE)
The following is the final example.
Example
import java.util.Calendar; public class Demo { public static void main(String[] args) { Calendar cal = Calendar.getInstance(); System.out.println("Year = " + cal.get(Calendar.YEAR)); System.out.println("Month = " + (cal.get(Calendar.MONTH) + 1)); System.out.println("Date = " + cal.get(Calendar.DATE)); } }
Output
Year = 2018 Month = 11 Date = 19
- Related Articles
- How to get current day, month and year in Java 8?
- How to get a Date from year, month and day in Java?
- Java Program to subtract year from current date
- MongoDB query to get specific month|year (not date)?
- Java Program to Get Current Date/Time
- Java Program to add year to current date using Calendar.add method
- Get week of month and year using Java Calendar
- Format MySQL date and convert to year-month-day
- MySQL query to fetch date with year and month?
- How to get first and last date of the current month with JavaScript?
- Java Program to Display current Date and Time
- How to get the current date and time in Java?
- How to get the current date in Java?
- How to convert year, month, and day of the month into a complete date in R?
- Java Program to get date for all the days of the current week

Advertisements