我必须检查一个日历中显示的日期是第二个日历中下一年的默认日期。 我试过以下但是日期没有正确显示
String str = executeJavascript1("return document.getElementById('EndDate').value;");
logMessage(str);
Calendar cal = Calendar.getInstance();
Date today = cal.getTime();
cal.add(Calendar.YEAR, 1); // to get previous year add -1
Date nextYear = cal.getTime();
SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("mm/dd/yyyy",Locale.ENGLISH);
String d = DATE_FORMAT.format(nextYear);
logMessage(d);
Assert.assertEquals(str,d);
答案 0 :(得分:-1)
你能这样做吗?
int year = cal.get(Calendar.YEAR);
int date = cal.get(Calendar.DATE);
int month= cal.get(Calender.MONTH);
Calendar cal2 = GregorianCalendar.getInstance();
c2.set(year+1, month, date );