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


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


WeekFields类的weekBasedYear()方法用于返回一个字段,以基于此WeekFields访问week-based-year的年份。该字段可与任何日历系统一起使用。

用法:

public TemporalField weekBasedYear()

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


返回值:此方法返回一个提供对week-based-year的访问权限的字段,而不是null。

以下示例程序旨在说明WeekFields.weekBasedYear()方法:
程序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.MONDAY, 1); 
  
        // apply weekBasedYear() 
        TemporalField weekBasedYear 
            = weekFields.weekBasedYear(); 
  
        // print results 
        System.out.println(weekBasedYear); 
    } 
}
输出:
WeekBasedYear[WeekFields[MONDAY, 1]]

程序2:

// 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://docs.oracle.com/javase/10/docs/api/java/time/temporal/WeekFields.html#weekBasedYear()



相关用法


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