當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java Calendar getWeeksInWeekYear()用法及代碼示例


java.util.Calendar 類的 getWeeksInWeekYear() 方法以整數形式返回一周年中的總周數。

用法

public int getWeeksInWeekYear()

參數

沒有傳遞參數。

返回

返回周年中的整數周數

拋出

UnsupportedOperationException:如果日曆中未定義任何周數。

例子1

import java.util.Calendar;
public class JavaCalendargetWeeksInWeekYearExample1 {    
    public static void main(String[] args){
		Calendar mycal = Calendar.getInstance();
		System.out.println(" Current Time:" + mycal.getTime());	
                System.out.println("Weeks in week year:"
				+ mycal.getWeeksInWeekYear());
		mycal.setWeekDate(1996, 23, 6 );
		System.out.println("Changed Time:"+mycal.getTime());
		System.out.println("Weeks in week year:"
				+ mycal.getWeeksInWeekYear());
}
}

輸出:

Current Time:Thu Aug 09 16:36:58 PDT 2018
Weeks in week year:52
Changed Time:Fri Jun 07 16:36:58 PDT 1996
Weeks in week year:52

例子2

import java.util.Calendar;
public class JavaCalendargetWeeksInWeekYearExample2 {
    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);
        int w = mycal.getWeeksInWeekYear();
        System.out.println("Week:" +w);
    }
    }

輸出:

Week:52
Weekayear :1969
Year :1969
Week:52



相關用法


注:本文由純淨天空篩選整理自 Java Calendar getWeeksInWeekYear() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。