Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Get days in a particular month

$
0
0

How do I get days of a particular month using java.util.Calendar.I have tried the code given below, but it gives me the days for the latest month and not the month I have given as input.I don't want to use a switch case.Can anyone please help?Thanks in advance!

public static void main(String args[]) throws ParseException {    Calendar cal = Calendar.getInstance();    int month = cal.get(Calendar.MONTH);    int year = cal.get(Calendar.YEAR);    if (month == 0) {        month = 3;        year = year-1;    }    String dateStart = "'"+ (year) +"-"+ (month) +"-1 00:00:00'";    String dateEnd = "'"+ (year) +"-"+ (month) +"-"+ cal.getMaximum(Calendar.DAY_OF_MONTH);    dateEnd = dateEnd +" 23:59:59'";    System.out.println("Start and End Date : "+ dateStart +" : "+ dateEnd);}

Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>