Java Yesterday getYesterdayDate(String format)

Here you can find the source of getYesterdayDate(String format)

Description

get Yesterday Date

License

Apache License

Declaration

public static String getYesterdayDate(String format) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {

    public static String getYesterdayDate(String format) {
        Calendar day = Calendar.getInstance();
        day.add(Calendar.DATE, -1);
        SimpleDateFormat sdf = new SimpleDateFormat(format);// "yyyy-MM-dd"
        String date = sdf.format(day.getTime());
        return date;
    }/*from ww w  .  j  a  v a 2  s  . c  o  m*/

    public static String format(Date aTs_Datetime) {
        return format(aTs_Datetime, "yyyy-MM-dd");
    }

    public static String format(Date aTs_Datetime, String as_Pattern) {
        if (aTs_Datetime == null || as_Pattern == null)
            return null;

        SimpleDateFormat dateFromat = new SimpleDateFormat();
        dateFromat.applyPattern(as_Pattern);

        return dateFromat.format(aTs_Datetime);
    }

    public static String getTime(Date date) {
        SimpleDateFormat formatter_f = new SimpleDateFormat("yyyy-MM-dd");
        String str = formatter_f.format(date);
        return str;
    }
}

Related

  1. getYesterday6AM()
  2. getYesterdayBegin()
  3. getYesterdayCompactTime()
  4. getYesterdayDate(Date date)
  5. getYesterdayDate(int day)
  6. getYesterdayDateAsString()
  7. getYesterdayFormat(String format)
  8. getYesterdayFormatString(String format)
  9. getYesterdaysDate()