How to add days into the date in android

前端 未结 10 1137
眼角桃花
眼角桃花 2020-12-01 12:07

In my database I am getting start date like 2011-11-30(yyyy/mm/dd)format.and duration date like 40 days.How can i calculate the days and get new date format of mm/dd/yyyy.

10条回答
  •  抹茶落季
    2020-12-01 12:36

    Date dtStartDate=o.getStartDate();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    Calendar c = Calendar.getInstance();
    c.setTime(dtStartDate);
    c.add(Calendar.DATE, 3);  // number of days to add
    String dt = sdf.format(c.getTime());  // dt is now the new date
    Toast.makeText(this, "" + dt, 5000).show();
    

提交回复
热议问题