Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

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

public class Main {
    /**
     * Returns the previous day of the passed {@link Date}
     *
     * @return The date - 24 hours
     */
    public static Date getYesterday(Date date) {
        if (date == null) {
            return getYesterday(new Date());
        }

        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.DAY_OF_WEEK, -1);

        return new Date(cal.getTimeInMillis());
    }
}