Java 日历 getMinimalDaysInFirstWeek()方法及示例
Calendar类中的 getMinimalDaysInFirstWeek() 方法用于返回所需年份第一周的最小天数。
语法:
public int getMinimalDaysInFirstWeek()
参数: 该方法不接受任何参数。
返回值: 该方法返回下一年第一周所需的最小天数。
以下程序说明了日历类的getMinimalDaysInFirstWeek()方法的工作情况:
例子1:
// Java code to illustrate
// getMinimalDaysInFirstWeek() method
import java.util.*;
public class Calendar_Demo {
public static void main(String args[])
{
// Creating a calendar
Calendar calndr
= new GregorianCalendar(2018, 6, 10);
// Getting the required minimal days
int min_days
= calndr.getMinimalDaysInFirstWeek();
// Displaying the results
System.out.println("The Minimal"
+ " days required: "
+ min_days);
}
}
输出
The Minimal days required: 1
例2:
// Java code to illustrate
// getMinimalDaysInFirstWeek() method
import java.util.*;
public class Calendar_Demo {
public static void main(String args[])
{
// Creating a calendar
Calendar calndr = Calendar.getInstance();
// Getting the required minimal days
int min_days
= calndr.getMinimalDaysInFirstWeek();
// Displaying the results
System.out.println("The Minimal"
+ " days required: "
+ min_days);
}
}
输出
The Minimal days required: 1
参考资料: https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#getMinimalDaysInFirstWeek-