Java Date to Month getMonthFirstDay(Date date)

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

Description

get Month First Day

License

Open Source License

Declaration

public static Date getMonthFirstDay(Date date) 

Method Source Code

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

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

public class Main {
    public static Date getMonthFirstDay(Date date) {
        return getDate(getDateYear(date), getDateMonth(date), 1);
    }/*from   w w w  .  j a  va  2s  .c  om*/

    public static Date getDate() {
        return Calendar.getInstance().getTime();
    }

    public static Date getDate(int year, int month, int day) {
        Calendar cal = Calendar.getInstance();
        cal.set(year, month - 1, day, 0, 0, 0);
        return cal.getTime();

    }

    public static Date getDate(int year, int month, int date, int hour, int mintue, int second) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month - 1);
        cal.set(Calendar.DATE, date);
        cal.set(Calendar.HOUR_OF_DAY, hour);
        cal.set(Calendar.MINUTE, mintue);
        cal.set(Calendar.SECOND, second);
        return cal.getTime();
    }

    public static int getDateYear(Date date) {

        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(Calendar.YEAR);
    }

    public static int getDateMonth(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(Calendar.MONTH) + 1;
    }
}

Related

  1. getMonth(String strDate)
  2. getMonthBeginDate()
  3. getMonthBetween(Date data1, Date data2)
  4. getMonthByOffset(Date date, int offset)
  5. getMonthDays(String date)
  6. getMonthFromDate(Date date)
  7. getMonthInterval(Date _one, Date _two)
  8. getMonthLastDate(Date date)
  9. getMonthLastDay(Date date)