Here you can find the source of getCurrentLastDate()
public static String getCurrentLastDate()
//package com.java2s; import java.text.*; import java.util.*; public class Main { private static String CurrentDate; public static String getCurrentLastDate() { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); Calendar calendar = null; try {//from w w w. jav a 2s.c o m java.util.Date date = formatter.parse(getCurrentFirstDate()); calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.MONTH, 1); calendar.add(Calendar.DAY_OF_YEAR, -1); return formatDate(calendar.getTime()); } catch (ParseException e) { e.printStackTrace(); } return null; } public static String getCurrentFirstDate() { Date NowDate = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-01"); CurrentDate = formatter.format(NowDate); return CurrentDate; } public static String formatDate(java.util.Date date) { return formatDateByFormat(date, "yyyy-MM-dd"); } public static int getTime(String sDateTime, String eDateTime) throws ParseException { SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd"); java.util.Date ssDateTime = myFormatter.parse(sDateTime); java.util.Date eeDateTime = myFormatter.parse(eDateTime); long l = (eeDateTime.getTime() - ssDateTime.getTime()); long day = l / (24 * 60 * 60 * 1000); return (int) day; } public static String formatDateByFormat(java.util.Date date, String format) { String result = ""; if (date != null) { try { SimpleDateFormat sdf = new SimpleDateFormat(format); result = sdf.format(date); } catch (Exception ex) { ex.printStackTrace(); } } return result; } }