Calculate Calendar time After - Android java.util

Android examples for java.util:Calendar

Description

Calculate Calendar time After

Demo Code


//package com.java2s;

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

public class Main {
    public static String timeAfter(String datestring, int after) {
        String afterDateString = "";
        Date date = null;//from  w  w  w.  ja v  a 2 s  .c om
        SimpleDateFormat df = new SimpleDateFormat("hh:mm");
        try {
            date = df.parse(datestring);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.add(Calendar.MINUTE, after);
            date = calendar.getTime();
            afterDateString = df.format(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return afterDateString;
    }
}

Related Tutorials