public static String getPastDate(int past) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - past); Date today = calendar.getTime(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); String result = format.format(today); return result;}此方法返回距今多少(past)天的日期(字符串表示)。
Calendar calendar = Calendar.getInstance();calendar.add(Calendar.MONTH, -1);//表示取上一个的月份信息
时间: 2024-11-02 00:16:38