Java Day of Month getLastDayOfMonth(Date date)

Here you can find the source of getLastDayOfMonth(Date date)

Description

get Last Day Of Month

License

Apache License

Declaration

public static String getLastDayOfMonth(Date date) 

Method Source Code


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

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Calendar;
import java.util.Date;

import java.util.HashMap;

import java.util.Map;

public class Main {
    private static final String dateFormat3 = "yyyy-MM-dd";
    private static final Map<String, DateFormat> DFS = new HashMap<String, DateFormat>();

    public static String getLastDayOfMonth(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);/*from  ww  w.  ja v  a  2s.co m*/
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DATE));
        return date2String(cal.getTime());
    }

    public static String date2String(Date date) {
        SimpleDateFormat formatter = new SimpleDateFormat(dateFormat3);
        String dateString = formatter.format(date);
        return dateString;
    }

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

    public static DateFormat getFormat(String pattern) {
        DateFormat format = DFS.get(pattern);
        if (format == null) {
            format = new SimpleDateFormat(pattern);
            DFS.put(pattern, format);
        }
        return format;
    }
}

Related

  1. getLastDayOfMonth(Calendar c)
  2. getLastDayOfMonth(Date currDate)
  3. getLastDayOfMonth(Date date)
  4. getLastDayOfMonth(Date date)
  5. getLastDayOfMonth(Date date)
  6. getLastDayOfMonth(Date date)
  7. getLastDayOfMonth(Date date)
  8. getLastDayOfMonth(Date dt)
  9. getLastDayOfMonth(Date firstDate)