Java TimeZone startOfYear(Date referenceDate, TimeZone timeZone)

Here you can find the source of startOfYear(Date referenceDate, TimeZone timeZone)

Description

Calculate the date at the start of the year for the given date.

License

Open Source License

Parameter

Parameter Description
referenceDate The given date.

Return

The calendar at the start of the year.

Declaration

public static Calendar startOfYear(Date referenceDate, TimeZone timeZone) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**//ww w.  j a  v a2  s . c  o  m
     * Calculate the date at the start of the year for the given date.
     * 
     * @param referenceDate The given date.
     * @return The calendar at the start of the year.
     */
    public static Calendar startOfYear(Date referenceDate, TimeZone timeZone) {
        Calendar c1 = Calendar.getInstance(timeZone);
        c1.setTime(referenceDate);

        Calendar c2 = Calendar.getInstance(timeZone);
        c2.clear();
        c2.set(c1.get(Calendar.YEAR), 0, 1);
        return c2;
    }
}

Related

  1. hasTimeComponent(Date date, TimeZone timeZone)
  2. midnight(Date date, TimeZone tz)
  3. monthOfYear(Date referenceDate, int month, TimeZone timeZone)
  4. normalizeDate(Date date, TimeZone timeZone)
  5. startOfNextDay(final Date date, final TimeZone timeZone)
  6. toEpoch(Date dateTime, String timeZone)