Java Calendar Month setTimeAsFirstDayOfMonth(Calendar calendar)

Here you can find the source of setTimeAsFirstDayOfMonth(Calendar calendar)

Description

set Time As First Day Of Month

License

Open Source License

Declaration

public static void setTimeAsFirstDayOfMonth(Calendar calendar) 

Method Source Code


//package com.java2s;
/*//from   w  ww .jav  a2  s.  c om
 * Copyright 2009 Yodlee, Inc.  All Rights Reserved.  Your use of this code 
 * requires a license from Yodlee.  Any such license to this code is 
 * restricted to evaluation/illustrative purposes only. It is not intended 
 * for use in a production environment, and Yodlee disclaims all warranties 
 * and/or support obligations concerning this code, regardless of the terms 
 * of any other agreements between Yodlee and you."
 */

import java.util.Calendar;

public class Main {
    public static final int FIRST_DAY_OF_MONTH = 1;

    public static void setTimeAsFirstDayOfMonth(Calendar calendar) {

        calendar.set(Calendar.DAY_OF_MONTH, FIRST_DAY_OF_MONTH);
        normalise(calendar);
    }

    public static void normalise(Calendar calendar) {

        Calendar tempCalendar = (Calendar) calendar.clone();
        calendar.clear();
        calendar.set(Calendar.YEAR, tempCalendar.get(Calendar.YEAR));
        calendar.set(Calendar.DAY_OF_YEAR, tempCalendar.get(Calendar.DAY_OF_YEAR));
    }
}

Related

  1. numberOfDaysInMonth(Calendar cal)
  2. sameMonth(Calendar one, Calendar two)
  3. setDate(Calendar cal, int month, int date)
  4. setDate(Calendar cal, int month, int date, boolean endOfDay)
  5. setDate(Calendar calendar, int month, int date)
  6. subtractMonths(Calendar date, int months)