Java Today getYestoday(String sourceDate, String format)

Here you can find the source of getYestoday(String sourceDate, String format)

Description

get Yestoday

License

Open Source License

Declaration

public static String getYestoday(String sourceDate, String format) 

Method Source Code

//package com.java2s;

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

public class Main {

    public static String getYestoday(String sourceDate, String format) {
        return getFormatDateAdd(getDateFromString(sourceDate, format), -1, format);
    }//from  www.  jav a2s . c o m

    public static String getFormatDateAdd(Date date, int amount, String format) {
        Calendar cal = new GregorianCalendar();
        cal.setTime(date);
        cal.add(GregorianCalendar.DATE, amount);
        return getFormatDateTime(cal.getTime(), format);
    }

    public static Date getDateFromString(String dateStr, String pattern) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        Date resDate = null;
        try {
            resDate = sdf.parse(dateStr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resDate;
    }

    public static String getFormatDateTime(Date date, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }
}

Related

  1. getTodayZero()
  2. getTodayZero()
  3. getTodayZeroHour()
  4. getTommorrow(String today)
  5. getYestoday()
  6. isBeforeToday(Date date)
  7. isBeforeToday(Date date)
  8. isGreaterThanToday(String dateString)
  9. isToday(Date d1)