Java Day of getFirstDay(Date date)

Here you can find the source of getFirstDay(Date date)

Description

get First Day

License

Open Source License

Declaration

static public Date getFirstDay(Date date) 

Method Source Code

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

import java.text.ParseException;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    /**/*from  www.j av  a  2  s .c o  m*/
     * format pattern : yyyy-MM-dd
     */
    public static final SimpleDateFormat FORMAT_YYYY_MM_DD = new SimpleDateFormat("yyyy-MM-dd");

    /**
     * Get first day of the month.
     * 
     * @param year
     *            the year
     * @param month
     *            the month
     * @return Date first day of the month.
     * @throws ParseException
     */
    static public Date getFirstDay(String year, String month) throws ParseException {
        return FORMAT_YYYY_MM_DD.parse(year + "-" + month + "-1");
    }

    static public Date getFirstDay(int year, int month) throws ParseException {
        return FORMAT_YYYY_MM_DD.parse(year + "-" + month + "-1");
    }

    static public Date getFirstDay(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(Calendar.DAY_OF_MONTH, 1);

        return c.getTime();
    }
}

Related

  1. getDeltaNow(int deltaDays)
  2. getDisplayDate(final Date date, final int offsetDays)
  3. getEndDayofMouth(String date, String inPattern, String outPattern)
  4. getFirstDay(boolean isNeedHH24MISS)
  5. getFirstDay(boolean withTime)
  6. getFirstDayInThisQuarter(String nowDate)
  7. getFirstDayOfQuarter(Date date)
  8. getFirstOfDay(Date date)
  9. getFirstTimeInDay(Date day)