获取当前日期并给当前日期增加天数 年数 月数

时间:2022-07-20 13:54:17

获取当前时间的 day 用int来保存

Date data = order.getOrderTime();
Calendar calendar = Calendar.getInstance();
calendar.setTime(data);

int i= calendar.get(Calendar.DAY_OF_MONTH);

获取当前日期并给当前日期增加天数 年数 月数

    Calendar c = Calendar.getInstance();
    SimpleDateFormat sdfDay = new SimpleDateFormat("yyyy-MM-dd");

    if("7天".equals(usetime[0])){
            c.add(Calendar.DAY_OF_MONTH, 7);
            p.put("duetime", sdfDay.format(c.getTime()));
            }else if("15天".equals(usetime[0])){
            c.add(Calendar.DAY_OF_MONTH, 15);
            p.put("duetime", sdfDay.format(c.getTime()));
            }else if("1个月".equals(usetime[0])){
            c.add(Calendar.MONTH, +1);
            p.put("duetime", sdfDay.format(c.getTime()));
            }else if("3个月".equals(usetime[0])){
            c.add(Calendar.MONTH, +3);
            p.put("duetime", sdfDay.format(c.getTime()));
            }else if("6个月".equals(usetime[0])){
            c.add(Calendar.MONTH, +6);
            p.put("duetime", sdfDay.format(c.getTime()));
            }else if("1年".equals(usetime[0])){
            c.add(Calendar.YEAR, +1);
            p.put("duetime", sdfDay.format(c.getTime()));

            }