Calendar類中的setFirstDayOfWeek(int day_val)方法用於在此Calendar中使用day_val設置一周的第一天。
用法:
public void set(int day_val)
參數:該方法采用整數類型的一個參數day_val,表示一周中的第一天。
返回值:該方法不返回任何值。
以下示例程序旨在說明Calendar類的setFirstDayOfWeek()方法的用法:
示例1:
// Java code to illustrate
// setFirstDayOfWeek() method
import java.util.*;
public class Calendar_Demo {
public static void main(String args[])
{
// Creating calendar object
Calendar calndr = Calendar.getInstance();
// Displaying first day of the week
int first_day = calndr.getFirstDayOfWeek();
System.out.println("The Current"
+ " First day of the week: "
+ first_day);
// Changing the first day of week
calndr.setFirstDayOfWeek(Calendar.THURSDAY);
// Displaying the alternate day
first_day = calndr.getFirstDayOfWeek();
System.out.println("The new first"
+ " day of the week: "
+ first_day);
}
}
輸出:
The Current First day of the week: 1 The new first day of the week: 5
示例2:
// Java code to illustrate
// setFirstDayOfWeek() method
import java.util.*;
public class Calendar_Demo {
public static void main(String args[])
{
// Creating calendar object
Calendar calndr
= new GregorianCalendar(2018, 6, 10);
// Displaying first day of the week
int first_day = calndr.getFirstDayOfWeek();
System.out.println("The"
+ " First day of the week: "
+ first_day);
// Changing the first day of week
calndr.setFirstDayOfWeek(Calendar.MONDAY);
// Displaying the alternate day
first_day = calndr.getFirstDayOfWeek();
System.out.println("The new first"
+ " day of the week: "
+ first_day);
}
}
輸出:
The First day of the week: 1 The new first day of the week: 2
參考: https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#setFirstDayOfWeek-int-
相關用法
- Java Calendar get()用法及代碼示例
- Java Calendar set()用法及代碼示例
- Java Calendar add()用法及代碼示例
- Java Calendar getMaximum()用法及代碼示例
- Java Calendar getActualMaximum()用法及代碼示例
- Java Calendar getLeastMaximum()用法及代碼示例
- Java Calendar getAvailableLocales()用法及代碼示例
- Java Calendar getInstance()用法及代碼示例
- Java Calendar getDisplayNames()用法及代碼示例
- Java Calendar getFirstDayOfWeek()用法及代碼示例
- Java Calendar getDisplayName()用法及代碼示例
- Java Calendar getActualMinimum()用法及代碼示例
- Java Calendar clear()用法及代碼示例
- Java Calendar clone()用法及代碼示例
- Java Calendar toString()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 Calendar setFirstDayOfWeek() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。