Java Month Get getMonthEnd(String strdate)

Here you can find the source of getMonthEnd(String strdate)

Description

get Month End

License

Open Source License

Parameter

Parameter Description
strdate a parameter

Declaration

public static String getMonthEnd(String strdate) 

Method Source Code


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

import java.util.Calendar;

public class Main {

    public static String getMonthEnd(String strdate) {
        java.util.Date date = parseDate(getMonthBegin(strdate));
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);//from  w  w  w  .j  a v  a 2s .c o m
        calendar.add(Calendar.MONTH, 1);
        calendar.add(Calendar.DAY_OF_YEAR, -1);
        return formatDate(calendar.getTime());
    }

    public static java.util.Date parseDate(String dateStr, String format) {

        java.util.Date date = null;
        try {
            java.text.DateFormat df = new java.text.SimpleDateFormat(format);
            date = (java.util.Date) df.parse(dateStr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }

    public static java.util.Date parseDate(String dateStr) {
        return parseDate(dateStr, "yyyy-MM-dd");
    }

    public static String getMonthBegin(String strdate) {
        java.util.Date date = parseDate(strdate);
        return format(date, "yyyy-MM") + "-01";
    }

    public static String formatDate(java.util.Date date) {
        return format(date, "yyyy-MM-dd");
    }

    public static String getTime(java.util.Date date) {
        return format(date, "HH:mm:ss");
    }

    public static String format(java.util.Date date, String format) {
        String result = "";
        try {
            if (date != null) {
                java.text.DateFormat df = new java.text.SimpleDateFormat(format);
                result = df.format(date);
            }
        } catch (Exception e) {
        }
        return result;
    }
}

Related

  1. getMonthBegin(String strdate)
  2. getMonthByNow(int month)
  3. getMonthCount(String from, String to)
  4. getMonthDesc(Date month)
  5. getMonthEnd(Date date)
  6. getMonthEnd(String strdate)
  7. getMonthEndDate(Date date)
  8. getMonthFirstDate(final Date date, final String format)
  9. getMonthForDate(String dateToCheck, String pattern)