Here you can find the source of getMonthEnd(String strdate)
Parameter | Description |
---|---|
strdate | a parameter |
public static String getMonthEnd(String strdate)
//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; } }