Java Year Ago yearAgo()

Here you can find the source of yearAgo()

Description

Get date for year ago

License

Apache License

Return

date

Declaration

public static Date yearAgo() 

Method Source Code


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

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

public class Main {
    /**//from  www.  j  av a 2s .  c o m
     * Get date for year ago
     *
     * @return date
     */
    public static Date yearAgo() {
        return forCalendarDiff(Calendar.YEAR, -1);
    }

    /**
     * Get date for calendar difference from current date
     *
     * @param field  difference field (Calendar.DATE, Calendar.MINUTE ... etc)
     * @param amount how much?
     * @return date for the difference
     */
    public static Date forCalendarDiff(int field, int amount) {
        GregorianCalendar gCal = new GregorianCalendar();
        gCal.add(field, amount);
        return new Date(gCal.getTimeInMillis());
    }
}

Related

  1. getHundredYearsAgo()
  2. hasYearPassed(int year)
  3. yearsAgo(int i)
  4. yearsAgo(int n)