get Last Day Of This Month - Android java.util

Android examples for java.util:Month

Description

get Last Day Of This Month

Demo Code


//package com.java2s;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {
    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

    public static String getLastDayOfThisMonth() {
        String str = "";
        Calendar lastDate = Calendar.getInstance();
        lastDate.set(Calendar.DATE, 1);//
        lastDate.add(Calendar.MONTH, 1);//
        lastDate.add(Calendar.DATE, -1);//

        str = sdf.format(lastDate.getTime());
        return str;
    }/*from  w w  w  .j  av a  2  s. c  o m*/
}

Related Tutorials