date After for date in yyyy/MM/dd format - Android java.util

Android examples for java.util:Date Format

Description

date After for date in yyyy/MM/dd format

Demo Code


//package com.java2s;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static String dateAfterHZ(String datestring, int after) {
        String afterDateString = "";
        Date date = null;//from   w  ww .  j  a  v a 2 s. c om
        SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
        try {
            date = df.parse(datestring);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.add(Calendar.DAY_OF_MONTH, after);
            date = calendar.getTime();
            afterDateString = df.format(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return afterDateString;
    }
}

Related Tutorials