Java Yesterday getYesterday()

Here you can find the source of getYesterday()

Description

get Yesterday

License

Open Source License

Declaration

public static Date getYesterday() 

Method Source Code

//package com.java2s;
/**// ww w  . jav  a  2s .  c  o  m
 * Copyright (c)2010-2011 Enterprise Website Content Management System(EWCMS), All rights reserved.
 * EWCMS PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * http://www.ewcms.com
 */

import java.text.SimpleDateFormat;

import java.util.Calendar;
import java.util.Date;

public class Main {
    private static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";

    public static Date getYesterday() {
        return getYesterday(DEFAULT_DATE_FORMAT);
    }

    public static Date getYesterday(String format) {
        SimpleDateFormat simple = new SimpleDateFormat(format);

        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -1);
        Date date = calendar.getTime();
        try {
            date = simple.parse(simple.format(date));
        } catch (Exception e) {
        }
        return date;
    }
}

Related

  1. getYesterday()
  2. getYesterday()
  3. getYesterday()
  4. getYesterday()
  5. getYesterday()