3
如何從日曆中JAVA如何從日曆獲得上週月在JAVA
如何從日曆中JAVA如何從日曆獲得上週月在JAVA
您可以使用getActualMaximum(Calendar.DAY_OF_MONTH)
得到的最後一天獲得每月的最後一週。將日曆日(月)設置爲該值,然後獲取星期幾。因此,你可以計算出「上週」的開始,無論對你來說意味着什麼(上週日?上週一?上週完整?)。
如果我理解你正確地是什麼意思,沿東西這行可能會做到這一點:
public static int getLastWeekInMonth(int year, int month) {
Calendar lastDayOfMonth = new GregorianCalendar();
//Set the date to the day before the 1:st day of the next month
lastDayOfMonth.set(year, month+1, 0);
return lastDayOfMonth.get(Calendar.WEEK_OF_YEAR);
}
你是什麼意思按周辦??? – 2010-07-29 13:44:56