Java Year Get getBeginningOfYear()

Here you can find the source of getBeginningOfYear()

Description

get Beginning Of Year

License

Apache License

Return

the first date of the current year (i.e. 01/01/XXXX @ 00:00:00)

Declaration

public static Date getBeginningOfYear() 

Method Source Code

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

import java.util.*;

public class Main {
    /**/*  www . j av a  2s. com*/
     * @return the first date of the current year (i.e. 01/01/XXXX @ 00:00:00)
     */
    public static Date getBeginningOfYear() {
        return getBeginningOfYear(null);
    }

    /**
     * @param date a date (if null, 'now' is assumed)
     * @return the first date of the year of <code>code</code> (i.e. 01/01/date.year @ 00:00:00)
     */
    public static Date getBeginningOfYear(Date date) {
        Calendar c = Calendar.getInstance();

        // if date is null, "c" is the current date
        if (date != null)
            c.setTime(date);

        c.set(Calendar.DAY_OF_MONTH, 1);
        c.set(Calendar.MONTH, 0);
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        return c.getTime();
    }
}

Related

  1. calcDifferenceAsYears(Calendar aBaseDate, Calendar aTargetDate)
  2. currentYear()
  3. currentYear()
  4. currentYearStr()
  5. getBeforeYear()
  6. getCalendarYearString(Calendar date)
  7. getCurrentYear()
  8. getCurrentYearAsInt()
  9. getCurrYearFirst()