Java Month Day 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;

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

public class Main {

    public static Date getMonthFirstDay(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);//  ww  w . ja  v  a 2s. co m
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH);

        c.clear();
        c.set(Calendar.YEAR, year);
        c.set(Calendar.MONTH, month);
        c.set(Calendar.DAY_OF_MONTH, 1);

        return c.getTime();
    }

    public static String getTime(Calendar c) {
        return getDate(c.getTime(), "HH:mm:ss");
    }

    public static String getDate() {
        return getDate(getCurDate(), "yyyy-MM-dd");
    }

    public static String getDate(Date date, String format) {

        String dtstr = "";
        if (date == null) {
            return dtstr;
        }

        if (format == null || "".equals(format.trim())) {
            format = "yyyy-MM-dd";
        }

        SimpleDateFormat sdf = new SimpleDateFormat(format);
        dtstr = sdf.format(date);
        return (dtstr == null ? "" : dtstr);

    }

    public static String getDate(Date date) {
        return getDate(date, "yyyy-MM-dd");
    }

    public static Date getDate(long time) {

        Calendar c = getCurCalendar();
        c.setTimeInMillis(time);

        return c.getTime();
    }

    public static Date getCurDate() {
        return getCurCalendar().getTime();
    }

    public static Calendar getCurCalendar() {
        return Calendar.getInstance();
    }
}

Related

  1. getMonthDay(int year, int month)
  2. getMonthEndDay(String time)
  3. getMonthEndDay(String yyyy, String mm)
  4. getMonthFirstDay()
  5. getMonthFirstDay()
  6. getMonthFirstDay(String date)
  7. getMonthFirstDay(T date)
  8. getMonthFristWeekSunday(String month)
  9. getMonthLastDay()