How do I get the last date of a month?

Bookmark this example!  
Category: java.util, viewed: 1339 time(s).

You want to know what is the last date for a current month. The code below show you how to get it.

 
package org.kodejava.example.util;
 
import java.util.Calendar;
 
public class LastDateOfMonth {
    public static void main(String[] args) {
	//
	// Get a calendar instance
	//
	Calendar calendar = Calendar.getInstance();
	
	//
	// Get the last date of the current month. To get the last date for a
	// specific month you can set the calendar month using calendar object
	// calendar.set(Calendar.MONTH, theMonth) method.
	//	
	int lastDate = calendar.getActualMaximum(Calendar.DATE);
	
	//
	// Print the current date and the last date of the month
	//
	System.out.println("Date     : " + calendar.getTime());
	System.out.println("Last Date: " + lastDate);
    }
}
 
 
Can't find what you are looking for? Join our FORUMS and ask some questions!

Most Viewed Examples

Latest Code Examples

100 Top & Latest


Locations of visitors to this page
eXTReMe Tracker
visitor stats
Get Chitika Premium