Java Yesterday getYesterDay(String pattern)

Here you can find the source of getYesterDay(String pattern)

Description

get Yester Day

License

Open Source License

Declaration

public static String getYesterDay(String pattern) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {

    public static String getYesterDay(String pattern) {
        SimpleDateFormat simpleFormate = new SimpleDateFormat(pattern);
        Calendar ca = Calendar.getInstance();
        ca.setTime(new Date());
        ca.add(Calendar.DAY_OF_YEAR, -1);
        return simpleFormate.format(ca.getTime());
    }/*from w  w  w.  j  ava2s  . co  m*/

    public static String format(java.util.Date date, String format) {
        String result = "";
        try {
            if (date != null) {
                java.text.DateFormat df = new java.text.SimpleDateFormat(format);
                result = df.format(date);
            }
        } catch (Exception e) {
        }
        return result;
    }

    public static String format(java.util.Date date) {
        return format(date, "yyyy/MM/dd");
    }

    public static String getTime(java.util.Date date) {
        return format(date, "HH:mm:ss");
    }
}

Related

  1. getYesterday()
  2. getYesterDay()
  3. getYesterday()
  4. getYesterday(Date date)
  5. getYesterday(Date date, Boolean isBefore, int interval)
  6. getYesterday6AM()
  7. getYesterdayBegin()
  8. getYesterdayCompactTime()
  9. getYesterdayDate(Date date)