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

Android examples for java.util:Day

Description

get Yesterday in yyyy.MM.dd format

Demo Code

import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.regex.Pattern;

public class Main{

    public static String getYesterday() {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd",
                Locale.US);/*from  w  ww. ja  v  a 2s .  c o m*/
        Date yesterday = new Date();
        yesterday.setTime(yesterday.getTime()
                - ((long) 1000 * 60 * 60 * 24));
        String dTime = formatter.format(yesterday);

        return dTime;
    }

}

Related Tutorials