Java Day of get1DayBeforDate()

Here you can find the source of get1DayBeforDate()

Description

get Day Befor Date

License

Open Source License

Declaration

public static String get1DayBeforDate() 

Method Source Code

//package com.java2s;

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

public class Main {

    public static String get1DayBeforDate() {

        Calendar now = Calendar.getInstance();
        now.set(Calendar.DAY_OF_MONTH, now.get(Calendar.DAY_OF_MONTH) - 1);

        return getDate(now.getTime(), "yyyy-MM-dd");
    }//  w  ww  . ja va 2s  . co  m

    public static String getDate() {
        return getDate(getCurDate(), "yyyy-MM-dd");
    }

    public static String getDate(Date date, String format) {

        String dtstr = "";
        if (date == null) {
            return dtstr;
        }

        if (format == null || "".equals(format.trim())) {
            format = "yyyy-MM-dd";
        }

        SimpleDateFormat sdf = new SimpleDateFormat(format);
        dtstr = sdf.format(date);
        return (dtstr == null ? "" : dtstr);

    }

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

    public static Date getDate(long time) {

        Calendar c = getCurCalendar();
        c.setTimeInMillis(time);

        return c.getTime();
    }

    public static String getTime(Calendar c) {
        return getDate(c.getTime(), "HH:mm:ss");
    }

    public static Date getCurDate() {
        return getCurCalendar().getTime();
    }

    public static Calendar getCurCalendar() {
        return Calendar.getInstance();
    }
}

Related

  1. endOfTheDay(Date date)
  2. formatDate(String day)
  3. formatDay(final Date time)
  4. formatDayTime(String day)
  5. formatShortNameOfDay(final Date date)
  6. get8BitTime(Date date, int deltaDay)
  7. getAfterDays(String date, String pattern, int afterDays)
  8. getAge(Date birthDay)
  9. getAgeOfCalendar(String birthDayString)