/** * 獲取上個月第一天 * @return */ public String getLastMonthFirstDayStr(){ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); cal.setTime(new Date() ); //獲取當(dāng)前時間上一個月 cal.add(Calendar.MONTH, -1); //獲取上個月的第一天 cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH)); return df.format(cal.getTime()); } /** * 獲取上個月最后一天 * @return */ public String getLastMonthLastDayStr(){ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); cal.setTime(new Date() ); //獲取當(dāng)前時間上一個月 cal.add(Calendar.MONTH, -1); //獲取上個月的最后一天 cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); return df.format(cal.getTime()); } /** * 獲取上周第一天 * @return */ public String getLastWeekFirstDayStr(){ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Calendar calWeek = Calendar.getInstance(); calWeek.setTime(new Date() ); int n1 = -1;// n為推遲的周數(shù),,-1上周,,0本周,1下周,,2下下周,,依次類推 calWeek.add(Calendar.DATE, n1 * 7); //上周周一 calWeek.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); return df.format(calWeek.getTime()); } /** * 獲取上周最后一天 * @return */ public String getLastWeekLastDayStr(){ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Calendar calWeek = Calendar.getInstance(); calWeek.setTime(new Date() ); int n1 = -1;// n為推遲的周數(shù),-1上周,,0本周,,1下周,2下下周,依次類推 calWeek.add(Calendar.DATE, n1 * 7); //上周周日 calWeek.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); return df.format(calWeek.getTime()); } public static void main(String[] args) { System.out.println(numberFormateDown(2,0.0)); |
|
來自: hongjing_z > 《Java》