当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java WeekFields getMinimalDaysInFirstWeek()用法及代码示例


WeekFields类的getMinimalDaysInFirstWeek()方法用于返回一个月或一年的第一周的最少天数。例如,ISO-8601需要4天(超过半周)的时间才能出现在计算第一周之前。此方法返回一个月或一年中第一周的最小天数,从1到7。

用法:

public int getMinimalDaysInFirstWeek()

参数:此方法不接受任何内容。


返回值:此方法返回一个月或一年中第一周的最小天数,从1到7。

以下示例程序旨在说明WeekFields.getMinimalDaysInFirstWeek()方法:
程序1:

// Java program to demonstrate 
// WeekFields.getMinimalDaysInFirstWeek() method 
  
import java.time.DayOfWeek; 
import java.time.temporal.WeekFields; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // create WeekFields 
        WeekFields weekFields 
            = WeekFields.of(DayOfWeek.SATURDAY, 2); 
  
        // apply getMinimalDaysInFirstWeek() 
        int noOfDays 
            = weekFields.getMinimalDaysInFirstWeek(); 
  
        // print results 
        System.out.println("Minimal number of days"
                           + " in the first week:"
                           + noOfDays); 
    } 
}
输出:
Minimal number of days in the first week:2

程序2:

// Java program to demonstrate 
// WeekFields.getMinimalDaysInFirstWeek() method 
  
import java.time.temporal.WeekFields; 
import java.util.Locale; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        Locale locale = new Locale("EN", "INDIA"); 
  
        // create WeekFields 
        WeekFields weekFields 
            = WeekFields.of(locale); 
  
        // apply getMinimalDaysInFirstWeek() 
        int noOfDays 
            = weekFields.getMinimalDaysInFirstWeek(); 
  
        // print results 
        System.out.println("Minimal number of days"
                           + " in the first week:"
                           + noOfDays); 
    } 
}
输出:
Minimal number of days in the first week:1

参考:https://docs.oracle.com/javase/10/docs/api/java/time/temporal/WeekFields.html#getMinimalDaysInFirstWeek()



相关用法


注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 WeekFields getMinimalDaysInFirstWeek() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。