📜  Java中的 Calendar getMinimalDaysInFirstWeek() 方法和示例

📅  最后修改于: 2022-05-13 01:55:20.589000             🧑  作者: Mango

Java中的 Calendar getMinimalDaysInFirstWeek() 方法和示例

Calendar 类中的getMinimalDaysInFirstWeek()方法用于返回所需年份的第一周所需的最少天数。
句法:

public int getMinimalDaysInFirstWeek()

参数:该方法不带任何参数。
返回值:该方法返回次年第一周所需的最少天数。
下面的程序说明了 Calendar 类的 getMinimalDaysInFirstWeek() 方法的工作:
示例 1:

Java
// 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);
    }
}


Java
// 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

示例 2:

Java

// 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: Java/util/Calendar.html#getMinimalDaysInFirstWeek–