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


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


java.util.Calendar 类的 getWeekYear() 方法是一个公共方法。此方法获取日历对象的周年并以整数形式返回日历的周年。

用法

public int getWeekYear()

参数

没有传递参数。

返回

返回当前日历对象的整数周年。

抛出

UnsupportedOperationException

例子1

import java.util.Calendar;


public class JavaCalendargetWeekYearExample1 {
    
    public static void main(String[] args){

		Calendar mycal = Calendar.getInstance();
		System.out.println(" Current Time:" + mycal.getTime());	
                System.out.println(" week year:"
				+ mycal.getWeekYear());
		mycal.setWeekDate(1996, 23, 6 );
		System.out.println("Changed Time:"+mycal.getTime());
		System.out.println("Weeks in week year:"
				+ mycal.getWeekYear());
    
}
}

输出:

Current Time:Fri Aug 10 10:52:54 PDT 2018
 week year:2018
Changed Time:Fri Jun 07 10:52:54 PDT 1996
Weeks in week year:1996

例子2

import java.util.Calendar;
public class JavaCalendargetWeekYearExample2 {
    public static void main(String args[])
    {
    
       Calendar mycal = Calendar.getInstance();
    mycal.setFirstDayOfWeek(Calendar.SUNDAY);
    mycal.setMinimalDaysInFirstWeek(7);
    mycal.setTimeInMillis(100);

    int wk = mycal.get(Calendar.WEEK_OF_YEAR);
    System.out.println("Week:" +wk);
    int wY = mycal.getWeekYear();
    System.out.println("Weekayear :" +wY);
    int y = mycal.get(Calendar.YEAR);
    System.out.println("Year :" +y);
      
   
    }
    }

输出:

Week:52
Weekayear :1969
Year :1969



相关用法


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