Here you can find the source of getMonthLastDay(String dateString)
Parameter | Description |
---|---|
dateString | String value of date |
public static Date getMonthLastDay(String dateString)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { /**/*from w w w . j ava 2s. c om*/ * return the last day of the date's month of specified string value in format: yyyy-MM * * @param dateString String value of date * @return Date value */ public static Date getMonthLastDay(String dateString) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM"); Date date = null; try { date = simpleDateFormat.parse(dateString); } catch (Exception e) { e.printStackTrace(); } Calendar calendar = Calendar.getInstance(); if (date != null) { calendar.setTime(date); } calendar.add(Calendar.MONTH, 1); calendar.add(Calendar.DATE, -1); return calendar.getTime(); } }