add Date By Hour - Android java.util

Android examples for java.util:Hour

Description

add Date By Hour

Demo Code


//package com.java2s;
import java.util.Calendar;
import java.util.Date;
import android.util.Log;

public class Main {
    public static Date addDateByHour(Date date, int hours) {
        Date ret = null;/*from   w ww  .  j a  v a2  s.  c om*/
        try {
            Calendar c = Calendar.getInstance();
            c.setTime(date);
            c.add(Calendar.HOUR_OF_DAY, hours);
            ret = c.getTime();
        } catch (IllegalArgumentException e) {
            Log.e("DateHelper",
                    "addDateByHour: IllegalArgumentException occured. ERR="
                            + e.getMessage());
        } catch (Exception e) {
            Log.e("DateHelper",
                    "addDateByHour: Error occured. ERR=" + e.getMessage());
        }
        return ret;
    }
}

Related Tutorials