public String[] getSingleWeek(String strDate, int intSingle){
String[] strWeekDays; Calendar cal = Calendar.getInstance();
int intYear = Integer.parseInt(strDate.substring(0,4));
int intMonth = Integer.parseInt(strDate.substring(4)) - 1;
cal.set(intYear, intMonth, 1); //
int intDay = cal.get(cal.DAY_OF_WEEK);
int intWeekNum = cal.get(cal.WEEK_OF_MONTH);
long longMillis = cal.getTimeInMillis(); //
if ( intWeekNum == intSingle ) {
strWeekDays = new String[8 - intDay];
for ( int i = 0; i < 8 - intDay; i ++) {
String strDateTemp = String.valueOf(cal.get(cal.DAY_OF_MONTH));
if (cal.get(cal.DAY_OF_MONTH) < 10) {
strDateTemp = "0" + strDateTemp;
}
strWeekDays[i] = strDate + strDateTemp;
longMillis += 24 * 60 * 60 * 1000;
cal.setTimeInMillis(longMillis);
}
}
else {
strWeekDays = new String[7];
longMillis += (intSingle - 2) * 7 * 24 * 60 * 60 * 1000 +
(7 - intDay) * 24 * 60 * 60 * 1000;
cal.setTimeInMillis(longMillis);
for ( int i = 0 ; i < 7 ; i ++) {
String strDateTemp = String.valueOf(cal.get(cal.DAY_OF_MONTH));
if (cal.get(cal.DAY_OF_MONTH) < 10) {
strDateTemp = "0" + strDateTemp;
}
strWeekDays[i] = strDate + strDateTemp;
longMillis += 24 *60 * 60 * 1000;
cal.setTimeInMillis(longMillis);
}
} //
return strWeekDays;
}
String[] strWeekDays; Calendar cal = Calendar.getInstance();
int intYear = Integer.parseInt(strDate.substring(0,4));
int intMonth = Integer.parseInt(strDate.substring(4)) - 1;
cal.set(intYear, intMonth, 1); //
int intDay = cal.get(cal.DAY_OF_WEEK);
int intWeekNum = cal.get(cal.WEEK_OF_MONTH);
long longMillis = cal.getTimeInMillis(); //
if ( intWeekNum == intSingle ) {
strWeekDays = new String[8 - intDay];
for ( int i = 0; i < 8 - intDay; i ++) {
String strDateTemp = String.valueOf(cal.get(cal.DAY_OF_MONTH));
if (cal.get(cal.DAY_OF_MONTH) < 10) {
strDateTemp = "0" + strDateTemp;
}
strWeekDays[i] = strDate + strDateTemp;
longMillis += 24 * 60 * 60 * 1000;
cal.setTimeInMillis(longMillis);
}
}
else {
strWeekDays = new String[7];
longMillis += (intSingle - 2) * 7 * 24 * 60 * 60 * 1000 +
(7 - intDay) * 24 * 60 * 60 * 1000;
cal.setTimeInMillis(longMillis);
for ( int i = 0 ; i < 7 ; i ++) {
String strDateTemp = String.valueOf(cal.get(cal.DAY_OF_MONTH));
if (cal.get(cal.DAY_OF_MONTH) < 10) {
strDateTemp = "0" + strDateTemp;
}
strWeekDays[i] = strDate + strDateTemp;
longMillis += 24 *60 * 60 * 1000;
cal.setTimeInMillis(longMillis);
}
} //
return strWeekDays;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货