Here you can find the source of getEndDateOfMonth(String yyyymmdd)
public static Date getEndDateOfMonth(String yyyymmdd)
//package com.java2s; /**/*from w ww .j a v a 2s . c om*/ * Copyright (c) 2008 OpenSprout Team. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * */ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static Date getEndDateOfMonth(String yyyymmdd) { SimpleDateFormat sformat = new SimpleDateFormat("yyyy-MM-dd"); String yyyymm = yyyymmdd.substring(0, 7); int year = Integer.parseInt(yyyymm.substring(0, 4)); int month = Integer.parseInt(yyyymm.substring(5)); String endDate = "31"; if (month == 2) if (year % 4 == 0) endDate = "29"; else endDate = "28"; else if (month % 2 == 0) endDate = "30"; Date date = null; try { date = sformat.parse(yyyymm + "-" + endDate); } catch (Exception e) { throw new RuntimeException(e); } return date; } public static Date getEndDateOfMonth(Date date) { return getEndDateOfMonth(makeYYYYMMWithHypon(date)); } public static String makeYYYYMMWithHypon(Date date) { DateFormat format = new SimpleDateFormat("yyyy-MM"); return format.format(date); } }