我正在尝试使用以下代码,但它每月都会返回错误的日期.
Calendar cal = Calendar.getInstance(); cal.setTime(sampleDay.getTime()); cal.set(Calendar.MONTH, sampleDay.get(Calendar.MONTH)+1); cal.set(Calendar.DAY_OF_MONTH, 0); return cal.getTime();
Argelbargel.. 17
获取本月的天数:
Calendar cal = Calendar.getInstance(); cal.setTime(sampleDay.getTime()); int noOfLastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
将日历设置为本月的最后一天:
Calendar cal = Calendar.getInstance(); cal.setTime(sampleDay.getTime()); cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
获取本月的天数:
Calendar cal = Calendar.getInstance(); cal.setTime(sampleDay.getTime()); int noOfLastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
将日历设置为本月的最后一天:
Calendar cal = Calendar.getInstance(); cal.setTime(sampleDay.getTime()); cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));