我正在尝试创建一个程序,它接受两个日期作为参数,并返回日期是否在本周,但我在调用isDateInCurrentWeek
. 当我尝试编译程序时,我收到一条错误消息
requestHoliday.java:16: isDateInCurrentWeek(java.util.GregorianCalendar) in requestHoliday cannot be applied to (java.util.Calendar)
if (isDateInCurrentWeek(startDate) && isDateInCurrentWeek(endDate));
.
import java.util.*;
import java.text.*;
public class hols {
public static void main( String[] args ) {
DateFormat df = new SimpleDateFormat("dd MM yyyy");
Date start = df.parse(args[0]);
Date end = df.parse(args[1]);
Calendar startDate = new GregorianCalendar();
Calendar endDate = new GregorianCalendar();
startDate.setTime(start);
endDate.setTime(end);
if( isDateInCurrentWeek( startDate ) && isDateInCurrentWeek( endDate ));
System.out.println( "Date is in current week!" );
}
public static boolean isDateInCurrentWeek(GregorianCalendar date) {
Calendar currentCalendar = GregorianCalendar.getInstance();
int week = currentCalendar.get(Calendar.WEEK_OF_YEAR);
int year = currentCalendar.get(Calendar.YEAR);
Calendar targetCalendar = GregorianCalendar.getInstance();
targetCalendar = date;
int targetWeek = targetCalendar.get(Calendar.WEEK_OF_YEAR);
int targetYear = targetCalendar.get(Calendar.YEAR);
return week == targetWeek && year == targetYear;
}
}
不太确定问题是什么,因为该方法将公历作为输入,并且两个日期采用公历格式。有人知道吗?