w3resource logo


Java Programming Exercies

Java DateTime, Calendar Exercises: Get the last date of the month

Secondary Nav

Java DateTime, Calendar : Exercise-8 with Solution

Write a Java program to get the last date of the month.

Java Code:

import java.util.*;
public class Exercise8 {
   public static void main(String[] args)
    {
        Calendar cal = Calendar.getInstance();
      //  cal.setTime(date);
	  System.out.println();
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
        System.out.println(cal.getTime());
		System.out.println();
    }
}

Sample Output :

Fri Sep 30 14:31:10 IST 2016 

Java Practice online:

import java.util.*;
public class Exercise8 {
   public static void main(String[] args)
    {
        Calendar cal = Calendar.getInstance();
      //  cal.setTime(date);
	  System.out.println();
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
        System.out.println(cal.getTime());
		System.out.println();
    }
}



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program