The Java implementation calculates how many days and weeks there are in a month

  • 2020-04-01 03:59:14
  • OfStack

import java.util.Calendar;

public class Test{
	public static void main(String[] args) {
		Calendar c = Calendar.getInstance();
		c.set(Calendar.YEAR, 2010); //In 2010,
		c.set(Calendar.MONTH, 5); //June
		System.out.println("------------" + c.get(Calendar.YEAR) + " years " + (c.get(Calendar.MONTH) + 1) + " The number of days and weeks of the month -------------");
		System.out.println(" Number of days: " + c.getActualMaximum(Calendar.DAY_OF_MONTH));
		System.out.println(" Weeks: " + c.getActualMaximum(Calendar.WEEK_OF_MONTH));
	}
}

Related articles: