阅读背景:

java获得当前日期的上个月的最后一天的日期&&每月的最大天数

来源:互联网 
// 获得当前时间所在月份的上个月的最后一天所在日期
	public String getLastMonthDay(Timestamp t) {
        Calendar cal = Calendar.getInstance();
        Date date = t;
        cal.setTime(date);
        int year = 0;
        int month = cal.get(Calendar.MONTH); // 上个月月份
       //设置年月
        if (month == 0) {
            year = cal.get(Calendar.YEAR) - 1;
            month = 12;
        } else {
            year = cal.get(Calendar.YEAR);
        }
        //设置天数
        String temp=year + "-" + month ;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
        Date d = null;
		try {
			d = format.parse(temp);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        cal.setTime(d);
        int day =cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        String endDay = year + "-" + month + "-" + day;
        return endDay;
    }// 获得当前时间所在月份的上个月的最后一天所在日期
	public String getLa



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: