Java Calendar Month getMonthBegin(Calendar calendar)

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

Description

get Month Begin

License

Open Source License

Declaration

public static Date getMonthBegin(Calendar calendar) 

Method Source Code

//package com.java2s;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    public static Date getMonthBegin(Calendar calendar) {
        if (calendar == null) {
            return null;
        }//  ww  w .ja v  a 2 s .  com

        Calendar date = new GregorianCalendar(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
                calendar.get(Calendar.DAY_OF_MONTH));

        int dm = date.get(Calendar.DAY_OF_MONTH);
        while (dm != 1) {
            date.add(Calendar.DATE, -1);
            dm = date.get(Calendar.DAY_OF_MONTH);
        }

        return date.getTime();
    }
}

Related

  1. getLastMonthDays(Calendar c)
  2. getMonth(Calendar c)
  3. getMonth(Calendar cal)
  4. getMonth(Calendar calendar)
  5. getMonthBegin(Calendar c)
  6. getMonthName(Calendar cal)
  7. getMonthStart(Calendar c)
  8. getMonthStart(Calendar cal)
  9. getMonthStr(Calendar cal)