![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Get the last day of month in Java
The getActualMaximum() method returns the maximum value that the specified calendar field could have, based on the time value of this Calendar.
Import the following package to work with Calendar class in Java,
import java.util.Calendar;
Create a calendar object.
Calendar cal = Calendar.getInstance();
Use the getActualMaximum() method to get the last day of the month.
int res = cal.getActualMaximum(Calendar.DATE);
The following is an example.
Example
import java.util.Calendar; public class Main { public static void main(String[] args) { Calendar cal = Calendar.getInstance(); int res = cal.getActualMaximum(Calendar.DATE); System.out.println("Today's Date = " + cal.getTime()); System.out.println("Last Date of the current month = " + res); } }
Output
Today's Date = Mon Nov 19 13:48:18 UTC 2018 Last Date of the current month = 30
Advertisements