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 setTimeZone()用法及代碼示例
- Java Calendar setFirstDayOfWeek()用法及代碼示例
- Java Calendar setTimeInMillis()用法及代碼示例
- Java Calendar setMinimalDaysInFirstWeek()用法及代碼示例
- Java Calendar setTimZone()用法及代碼示例
- Java Calendar set()用法及代碼示例
- Java Calendar setTime()用法及代碼示例
- Java Calendar setLenient()用法及代碼示例
- Java Calendar get()用法及代碼示例
- Java Calendar add()用法及代碼示例
- Java Calendar getWeekYear()用法及代碼示例
- Java Calendar computeFields()用法及代碼示例
- Java Calendar after()用法及代碼示例
- Java Calendar complete()用法及代碼示例
- Java Calendar compareTo()用法及代碼示例
- Java Calendar getDisplayName()用法及代碼示例
- Java Calendar getGreatestMinimum()用法及代碼示例
- Java Calendar clear()用法及代碼示例
- Java Calendar roll(int calndr_field, int amt)用法及代碼示例
- Java Calendar clear(int cal_field)用法及代碼示例
注:本文由純淨天空篩選整理自 Java Calendar setWeekDate() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。