SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar calendar = new GregorianCalendar(); calendar.setTime(date); //获得本月第一天 calendar.add(Calendar.MONTH, 0); calendar.set(Calendar.DAY_OF_MONTH, 1);
// 时间戳转换成字符串格式 startTime = sdf.format(calendar.getTime()); Calendar calendar2 = new GregorianCalendar(); calendar2.setTime(date); //获得本月最大的一天 calendar2.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); // 获取当前日期 endTime = sdf.format(calendar2.getTime());
标签:第一天,calendar2,本月,MONTH,获取,new,calendar,Calendar From: https://www.cnblogs.com/Objecting/p/17144218.html