get Date Before Yesterday - Java java.util

Java examples for java.util:Day

Description

get Date Before Yesterday

Demo Code


//package com.java2s;

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

public class Main {
    public static void main(String[] argv) throws Exception {
        Date currentDate = new Date();
        System.out.println(getDateBeforeYesterday(currentDate));
    }//www. ja v  a  2  s .  com

    public static Date getDateBeforeYesterday(Date currentDate) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(currentDate);
        calendar.add(Calendar.DAY_OF_YEAR, -2);
        return calendar.getTime();
    }
}

Related Tutorials