java.util.Calendar.setFirstDayOfWeek(int)方法範例


java.util.Calendar.setFirstDayOfWeek(int) 方法設定一週的第一天。

宣告

以下是java.util.Calendar.setFirstDayOfWeek()方法的宣告

public void setFirstDayOfWeek(int value)

引數

  • value -- 給定的一週的第一天。

返回值

此方法不返回任何值。

異常

  • NA

例子

下面的範例演示java.util.calendar.setFirstDayOfWeek()方法的用法。

package com.yiibai;

import java.util.*;

public class CalendarDemo {

   public static void main(String[] args) {

      // create a calendar
      Calendar cal = Calendar.getInstance();

      // print current first day of the week
      int day = cal.getFirstDayOfWeek();
      System.out.println("Current first day of the week:" + day);

      // set first day of the week as something else
      cal.setFirstDayOfWeek(Calendar.WEDNESDAY);

      // print altered first day of the week
      day = cal.getFirstDayOfWeek();;
      System.out.println("Altered first day of the week:" + day);
   }
}

讓我們來編譯和執行上面的程式,這將產生以下結果:

Current first day of the week:2
Altered first day of the week:4