get Yesterday's Date - Android java.util

Android examples for java.util:Day

Description

get Yesterday's Date

Demo Code


//package com.java2s;

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static Date getYesterday(Date from) {
        Calendar c = buildFromDate(from);
        c.add(Calendar.DATE, -1); // number of days to add
        return c.getTime();
    }/* ww w.  ja  v  a 2s .  c om*/

    private static Calendar buildFromDate(Date from) {
        Calendar c = Calendar.getInstance();
        c.setTime(from);
        return c;
    }
}

Related Tutorials