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 getWeeksInWeekYear()用法及代碼示例
- Java Calendar get()用法及代碼示例
- Java Calendar getDisplayName()用法及代碼示例
- Java Calendar getGreatestMinimum()用法及代碼示例
- Java Calendar getCalendarType()用法及代碼示例
- Java Calendar getAvailableLocales()用法及代碼示例
- Java Calendar getInstance()用法及代碼示例
- Java Calendar getLeastMaximum()用法及代碼示例
- Java Calendar getTime()用法及代碼示例
- Java Calendar getMinimum()用法及代碼示例
- Java Calendar getActualMaximum()用法及代碼示例
- Java Calendar getAvailableCalendarTypes()用法及代碼示例
- Java Calendar getTimeInMillis()用法及代碼示例
- Java Calendar getMaximum()用法及代碼示例
- Java Calendar getFirstDayOfWeek()用法及代碼示例
- Java Calendar getActualMinimum()用法及代碼示例
- Java Calendar getDisplayNames()用法及代碼示例
- Java Calendar getTimeZone()用法及代碼示例
- Java Calendar getMinimalDaysInFirstWeek()用法及代碼示例
- Java Calendar add()用法及代碼示例
注:本文由純淨天空篩選整理自 Java Calendar getWeekYear() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。