简体   繁体   中英

calculate 3 months after the date - Android

I want to calculate 4 months after the date I pulled from the database. How can I do that. The output of history is as follows.

Wed Nov 27 14:42:23 GMT+03:00 2019

  JSONObject form_tarih2 = jObj.getJSONObject("form_tarih2");
        String date = form_tarih2.getString("date");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
        Date calculateDate = sdf.parse(date);

Try this:

JSONObject form_tarih2 = jObj.getJSONObject("form_tarih2");
String date = form_tarih2.getString("date");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
Date calculateDate = sdf.parse(date);

final Calendar calendar = Calendar.getInstance();
calendar.setTime(calculateDate);
calendar.add(Calendar.MONTH,4);

You can add/sub days, months, year etc according to your need using Calendar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM