Java Yesterday yesterday()

Here you can find the source of yesterday()

Description

yesterday

License

LGPL

Declaration

public static Date yesterday() 

Method Source Code

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

import java.util.*;

public class Main {
    /**/*from  ww w.j  av a  2 s  .  c o  m*/
     * Milliseconds=14 *
     */
    public static final int MILLISECOND = Calendar.MILLISECOND;
    /**
     * Seconds=13 *
     */
    public static final int SECOND = Calendar.SECOND;
    /**
     * Minute=12 *
     */
    public static final int MINUTE = Calendar.MINUTE;
    /**
     * Hour=11 *
     */
    public static final int HOUR = Calendar.HOUR_OF_DAY;
    /**
     * Day=5 *
     */
    public static final int DAY = Calendar.DAY_OF_MONTH;

    public static Date yesterday() {
        final Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(DAY, -1);
        // zero time (hour, minutes, seconds, milliseconds)
        calendar.set(Calendar.HOUR, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }
}

Related

  1. isYesterday(Date date)
  2. yesterday()
  3. yesterday()
  4. yesterday()
  5. yesterDay()
  6. yesterday()
  7. yesterday()
  8. yesterday(Date date)
  9. yesterday(int daybefore, String pattern)