Java Month Day getCurMonthFirstDay()

Here you can find the source of getCurMonthFirstDay()

Description

get Cur Month First Day

License

Open Source License

Declaration

public static String getCurMonthFirstDay() 

Method Source Code


//package com.java2s;

import java.text.DateFormat;

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    public static final String dateFormat = "yyyy-MM-dd";

    public static String getCurMonthFirstDay() {
        Calendar cal = Calendar.getInstance();
        Date d = new Date();
        cal.setTime(d);/*from  www . j a v a 2s.c  om*/
        cal.set(Calendar.DATE, 1);
        return dateFormat(cal.getTime());
    }

    public static String getCurMonthFirstDay(String date) {
        Date d = strToDtSimpleFormat(date);
        Calendar cal = Calendar.getInstance();
        cal.setTime(d);
        cal.set(Calendar.DATE, 1);
        return dateFormat(cal.getTime());
    }

    public static final String dateFormat(Date date) {
        if (date == null) {
            return "";
        }
        return getFormat(dateFormat).format(date);
    }

    public static final Date strToDtSimpleFormat(String strDate) {
        if (strDate == null) {
            return null;
        }

        try {
            return getFormat(dateFormat).parse(strDate);
        } catch (Exception e) {
        }

        return null;
    }

    public static final String format(Date date, String formate) {
        if (date == null) {
            return "";
        }
        return getFormat(formate).format(date);
    }

    public static final String format(Long dateTmie, String formate) {
        Date date = new Date(dateTmie);
        return getFormat(formate).format(date);
    }

    public static final DateFormat getFormat(String format) {
        return new SimpleDateFormat(format);
    }
}

Related

  1. daysInMonth(GregorianCalendar c)
  2. firstDayOfMonth(Date date)
  3. firstDayOfMonth(Date date)
  4. firstMonthDay(String dateTime, int num)
  5. getActualMaximumDayOfMonth(final Date date)
  6. getCurrentDayOfMonth()
  7. getCurretnMonthFirstDay()
  8. getCurrMonthFirstDay()
  9. getDayOfMonth()