Java Month Calculate alignMonth(Calendar timestamp)

Here you can find the source of alignMonth(Calendar timestamp)

Description

Aligns the time fields to the start of the month.

License

Apache License

Parameter

Parameter Description
timestamp The calendar to align.

Return

The parameter.

Declaration

public static Calendar alignMonth(Calendar timestamp) 

Method Source Code

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

import java.util.*;

public class Main {
    /**/* w w w  .  ja va 2 s.c  o  m*/
     * Aligns the time fields to the start of the month.
     * @param timestamp The calendar to align.
     * @return The parameter.
     */
    public static Calendar alignMonth(Calendar timestamp) {
        timestamp.set(Calendar.DAY_OF_MONTH, 1);
        return alignDay(timestamp);
    }

    /**
     * Aligns the time fields to the start of the day.
     * @param timestamp The calendar to align.
     * @return The parameter.
     */
    public static Calendar alignDay(Calendar timestamp) {
        timestamp.set(Calendar.HOUR_OF_DAY, 0);
        timestamp.set(Calendar.MINUTE, 0);
        timestamp.set(Calendar.SECOND, 0);
        timestamp.set(Calendar.MILLISECOND, 0);
        return timestamp;
    }
}

Related

  1. beforeAMonth()
  2. calendarMonthToInt(int calendarMonth)
  3. currentMonth()
  4. divideIntoMonthlyIntervals(Date start, Date end)