位置:首页 > Java技术 > Java.util包 > java.util.Calendar.setFirstDayOfWeek(int)方法实例

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