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

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

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

WeekFields 类getFirstDayOfWeek()方法用于将一周中的第一天作为 DayOfWeek 枚举返回。例如,美国使用星期日,而法国使用星期一。

句法:

public DayOfWeek getFirstDayOfWeek()

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

返回值:此方法返回星期几,不为空。

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

// Java program to demonstrate
// WeekFields.getFirstDayOfWeek() 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.MONDAY, 1);
  
        // apply getFirstDayOfWeek()
        DayOfWeek firstDay
            = weekFields.getFirstDayOfWeek();
  
        // print results
        System.out.println("First Day:"
                           + firstDay);
    }
}
输出:
First Day:MONDAY

方案二:

// Java program to demonstrate
// WeekFields.getFirstDayOfWeek() method
  
import java.time.DayOfWeek;
import java.time.temporal.WeekFields;
import java.util.Locale;
  
public class GFG {
    public static void main(String[] args)
    {
  
        Locale locale = new Locale("EN", "US");
  
        // create WeekFields
        WeekFields weekFields
            = WeekFields.of(locale);
  
        // apply getFirstDayOfWeek()
        DayOfWeek firstDay
            = weekFields.getFirstDayOfWeek();
  
        // print results
        System.out.println("First Day:"
                           + firstDay);
    }
}
输出:
First Day:SUNDAY

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