Java Month Day getMonthFirstDay()

Here you can find the source of getMonthFirstDay()

Description

get Month First Day

License

Apache License

Declaration

public static Date getMonthFirstDay() throws ParseException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {

    public static Date getMonthFirstDay() throws ParseException {
        int mondayPlus;
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        cal.set(Calendar.DAY_OF_MONTH, 1);
        return getDate(cal.getTime());

    }/*from w w w .j a v a2 s. c om*/

    public static Date getDate(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            return sdf.parse(sdf.format(date));
        } catch (ParseException e) {
            return null;
        }
    }

    public static Date getDate(Date date, String dateFormat) {
        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
        try {
            return sdf.parse(sdf.format(date));
        } catch (ParseException e) {
            return null;
        }
    }

    public static Date getDate(String date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            return sdf.parse(date);
        } catch (ParseException e) {
            return null;
        }
    }

    public static Date getDate(String date, String dateFormat) {
        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
        try {
            return sdf.parse(date);
        } catch (ParseException e) {
            return null;
        }
    }

    public static Date getTime(String date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.parse(date);
    }
}

Related

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