怎样获得当月最后一天?
GregorianCalendar c = new GregorianCalendar();
c.setTime(toDate);
c.add(Calendar.DATE, 1);
sql.append((where++ > 0 ? "AND" : "WHERE")
+ " USER_DATE < TO_DATE('" + sdf.format(c.getTime())
+ "','MM/dd/yyyy') ");
改写获得toDate所在月最后一天。谢谢!
[解决办法]
Date date = new Date();// 获取年 int year = date.getYear() + 1900; //月 int month = date.getMonth();Date lastDate = new Date(year, month + 1, 0);//当前月最后一天
[解决办法]
up3楼
[解决办法]
Calendar cal = Calendar.getInstance();
cal.setTime(toDate);
int month = cal.get(Calendar.MONTH+1); // 本月月份
int day = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
[解决办法]
Calendar lastDate = Calendar.getInstance();
lastDate.set(Calendar.DATE, 1);// 设为当前月的1号
lastDate.add(Calendar.MONTH, 1);// 加一个月,变为下月的1号
lastDate.add(Calendar.DATE, -1);// 减去一天,变为当月最后一天