SimpleDateFormat format = new SimpleDateFormat('yyyy-MM-dd'); //獲取前月的第一天 Calendar cal_1=Calendar.getInstance();//獲取當(dāng)前日期 cal_1.add(Calendar.MONTH, -1); cal_1.set(Calendar.DAY_OF_MONTH,1);//設(shè)置為1號,當(dāng)前日期既為本月第一天 firstDay = format.format(cal_1.getTime()); System.out.println('-----1------firstDay:'+firstDay); //獲取前月的最后一天 Calendar cale = Calendar.getInstance(); cale.set(Calendar.DAY_OF_MONTH,0);//設(shè)置為1號,當(dāng)前日期既為本月第一天 lastDay = format.format(cale.getTime()); System.out.println('-----2------lastDay:'+lastDay); //獲取當(dāng)前月第一天: Calendar c = Calendar.getInstance(); c.add(Calendar.MONTH, 0); c.set(Calendar.DAY_OF_MONTH,1);//設(shè)置為1號,當(dāng)前日期既為本月第一天 String first = format.format(c.getTime()); System.out.println('===============first:'+first); //獲取當(dāng)前月最后一天 Calendar ca = Calendar.getInstance(); ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH)); String last = format.format(ca.getTime()); System.out.println('===============last:'+last); /** * 字符串的日期格式的計算 */ public static int daysBetween(String smdate,String bdate) throws ParseException{ SimpleDateFormat sdf=new SimpleDateFormat('yyyy-MM-dd'); Calendar cal = Calendar.getInstance(); cal.setTime(sdf.parse(smdate)); long time1 = cal.getTimeInMillis(); cal.setTime(sdf.parse(bdate)); long time2 = cal.getTimeInMillis(); long between_days=(time2-time1)/(1000*3600*24); return Integer.parseInt(String.valueOf(between_days)); }
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點擊舉報。