您好,欢迎访问一九零五行业门户网

如何在Java中找到特定年份的某个月份的天数?

a gregoriancalendar is a concrete subclass of calendar class and it provides the standard calendar system used by most of the world. in java, this gregoriancalendar can handle both the gregorian calendar as well as julian calendar. we can determine or find the number of days in a month of a particular year by using the getactualmaximum() method of gregoriancalendar class. this method returns the maximum value that the gregoriancalendar field can have. the parameter can be any field of a calendar class.
syntaxpublic int getactualmaximum(int field)
exampleimport java.util.*;public class noofdaysinamonthofayeartest { public static void main(string []args) { for (int i = 2000; i < 2018; i++) { calendar calendar = new gregoriancalendar(i, calendar.february, 1); int numberofdays = calendar.getactualmaximum(calendar.day_of_month); system.out.println("february " + i + ": " + numberofdays + " days"); } }}
输出february 2000: 29 daysfebruary 2001: 28 daysfebruary 2002: 28 daysfebruary 2003: 28 daysfebruary 2004: 29 daysfebruary 2005: 28 daysfebruary 2006: 28 daysfebruary 2007: 28 daysfebruary 2008: 29 daysfebruary 2009: 28 daysfebruary 2010: 28 daysfebruary 2011: 28 daysfebruary 2012: 29 daysfebruary 2013: 28 daysfebruary 2014: 28 daysfebruary 2015: 28 daysfebruary 2016: 29 daysfebruary 2017: 28 days
以上就是如何在java中找到特定年份的某个月份的天数?的详细内容。
其它类似信息

推荐信息