get Yesterday in format yyyy/MM/dd - Android java.util

Android examples for java.util:Day

Description

get Yesterday in format yyyy/MM/dd

Demo Code


//package com.java2s;
import android.annotation.SuppressLint;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import java.util.GregorianCalendar;

public class Main {
    @SuppressLint("SimpleDateFormat")
    public static String getYesterday() {
        Calendar cal = new GregorianCalendar();
        cal.add(Calendar.DATE, -1);
        return new SimpleDateFormat("yyyy/MM/dd").format(cal.getTime());
    }//from w  w w .ja v  a2 s.co m

    @SuppressLint("SimpleDateFormat")
    public static String getYesterday(String strFormat) {
        Calendar cal = new GregorianCalendar();
        cal.add(Calendar.DATE, -1);
        return new SimpleDateFormat(strFormat).format(cal.getTime());
    }
}

Related Tutorials