📌  相关文章
📜  Java中的 WeekFields weekBasedYear() 方法及示例

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

Java中的 WeekFields weekBasedYear() 方法及示例

WeekFields 类weekBasedYear()方法用于返回一个字段,以根据此 WeekFields 访问基于周的年份的年份。该字段可用于任何日历系统。

句法:

public TemporalField weekBasedYear()

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

返回值:此方法返回一个提供对基于周的年份的访问的字段,而不是 null。

下面的程序说明了 WeekFields.weekBasedYear() 方法:
方案一:

// Java program to demonstrate
// WeekFields.weekBasedYear() method
  
import java.time.DayOfWeek;
import java.time.temporal.TemporalField;
import java.time.temporal.WeekFields;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create WeekFields
        WeekFields weekFields
            = WeekFields.of(DayOfWeek.MONDAY, 1);
  
        // apply weekBasedYear()
        TemporalField weekBasedYear
            = weekFields.weekBasedYear();
  
        // print results
        System.out.println(weekBasedYear);
    }
}
输出:
WeekBasedYear[WeekFields[MONDAY, 1]]

方案二:

// Java program to demonstrate
// WeekFields.weekBasedYear() method
  
import java.time.DayOfWeek;
import java.time.temporal.TemporalField;
import java.time.temporal.WeekFields;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create WeekFields
        WeekFields weekFields
            = WeekFields.of(DayOfWeek.SUNDAY, 1);
  
        // apply weekBasedYear()
        TemporalField weekBasedYear
            = weekFields.weekBasedYear();
  
        // print results
        System.out.println(weekBasedYear);
    }
}
输出:
WeekBasedYear[WeekFields[SUNDAY, 1]]

参考资料:https: Java/time/temporal/WeekFields.html#weekBasedYear()