Java TimeZone monthOfYear(Date referenceDate, int month, TimeZone timeZone)

Here you can find the source of monthOfYear(Date referenceDate, int month, TimeZone timeZone)

Description

Utility function to get the start of the month as a Calendar.

License

Open Source License

Parameter

Parameter Description
referenceDate The whole date.
month The month to calculate the start of. 1 is January, 12 is December.

Return

The start of the month.

Declaration

public static Calendar monthOfYear(Date referenceDate, int month, 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 {
    /**/*from  ww w  .j a va2  s. c o  m*/
     * Utility function to get the start of the month as a Calendar.
     * 
     * @param referenceDate The whole date.
     * @param month The month to calculate the start of. 1 is January, 
     *       12 is December.
     * 
     * @return The start of the month.
     */
    public static Calendar monthOfYear(Date referenceDate, int month, TimeZone timeZone) {
        Calendar c1 = Calendar.getInstance(timeZone);
        c1.setTime(referenceDate);

        Calendar c2 = Calendar.getInstance(timeZone);
        c2.clear();

        // Adjust for Java 0 based months.
        c2.set(c1.get(Calendar.YEAR), month - 1, 1);

        return c2;
    }
}

Related

  1. getTimezoneDate(String stateCode)
  2. getTimeZoneOffset(Date d)
  3. getTimezoneOffsetInHours(Date date)
  4. hasTimeComponent(Date date, TimeZone timeZone)
  5. midnight(Date date, TimeZone tz)
  6. normalizeDate(Date date, TimeZone timeZone)
  7. startOfNextDay(final Date date, final TimeZone timeZone)
  8. startOfYear(Date referenceDate, TimeZone timeZone)
  9. toEpoch(Date dateTime, String timeZone)