当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Calendar setWeekDate()用法及代码示例


java.util.Calendar 类的 setWeekDate() 方法以指定的整数值作为参数设置当前日期。这些值是 weekYear、weekOfYear 和 dayOfWeek。

用法

public void setWeekDate(int weekYear, int weekOfYear, int dayOfWeek)

参数

weekYear- 周年

weekOfYear- 基于 weekYear 的周数

dayOfWeek- 星期几值:

返回

NA

抛出

NA

例子1

import java.util.Calendar;
public class JavaCalendarsetWeekDateExample1 {
	public static void main(String[] args){
                             // creating new calendar object mycal
		Calendar mycal = Calendar.getInstance();
              //by using getTime method geting the Todays Time 
		System.out.println("  Time Today:" + mycal.getTime());
                // setting the weekyear , weekofyear and dayofweek using setWeekDate
		mycal.setWeekDate(1996, 23, 6);
		System.out.println("Now Time Today:"+mycal.getTime());	
	}
}

输出:

Time Today:Sat Aug 18 10:57:54 PDT 2018
Now Time Today:Fri Jun 07 10:57:54 PDT 1996

例子2

import java.util.Calendar;
public class JavaCalendarsetWeekDateExample2 {
	public static void main(String[] args){
             // creating  2 new calendar object mycal andmycal2
		Calendar mycal = Calendar.getInstance();
                Calendar mycal2 = Calendar.getInstance();
              //by using getTime method geting the Todays Time 
		System.out.println("  Time Today(mycal):" + mycal.getTime());
                int woy = mycal.get(Calendar.WEEK_OF_YEAR);
                 int dow = mycal.get(Calendar.DAY_OF_WEEK);
                 int wy = mycal.get(Calendar.YEAR);
                // setting the weekyear , weekofyear and dayofweek using setWeekDate
		mycal2.setWeekDate(wy , woy , dow);
		System.out.println("Time Today (mycal2):"+mycal2.getTime());
	}
}

输出:

Time Today(mycal):Sat Aug 18 11:21:42 PDT 2018
Time Today (mycal2):Sat Aug 18 11:21:42 PDT 2018

相关用法


注:本文由纯净天空筛选整理自 Java Calendar setWeekDate() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。