Java Month Day getMonthFirstDay()

Here you can find the source of getMonthFirstDay()

Description

get Month First Day

License

Apache License

Declaration

@SuppressWarnings("deprecation")
public static String getMonthFirstDay() 

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 {

    @SuppressWarnings("deprecation")
    public static String getMonthFirstDay() {
        Date date = new Date();
        int nowMonth = date.getMonth() + 1;
        int nowYear = date.getYear() + 1900;
        String startTime = nowYear + "-" + nowMonth + "-1";
        return startTime;
    }/*from  w w  w  .ja  v a  2s  .c  o  m*/

    public static String getYear() {
        return getDateString("yyyy");
    }

    public static String getDateString() {
        return getDateString("yyyy-MM-dd");
    }

    public static String getDateString(int after) {
        return addDay(getDateString("yyyy-MM-dd"), after);
    }

    public static String getDateString(String format) {
        SimpleDateFormat df = new SimpleDateFormat(format);
        Date date = new Date(System.currentTimeMillis());
        String dateStr = df.format(date);
        return dateStr;
    }

    public static String addDay(String beginDateStr, int adddaycount) {
        java.text.SimpleDateFormat format = new java.text.SimpleDateFormat(
                "yyyy-MM-dd");
        try {
            Date beginDate = format.parse(beginDateStr);
            Calendar cal = Calendar.getInstance();
            cal.setTime(beginDate);
            cal.add(Calendar.DATE, adddaycount);
            Date enddate = cal.getTime();
            return format.format(enddate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Date addDay(Date beginDate, int addcount) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(beginDate);
        cal.add(Calendar.DAY_OF_YEAR, addcount);
        Date enddate = cal.getTime();
        return enddate;
    }
}

Related

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