當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。