get Last Day Of Month - Android java.util

Android examples for java.util:Month

Description

get Last Day Of Month

Demo Code


//package com.java2s;

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

import java.util.GregorianCalendar;

public class Main {

    public static String getLastDayOfMonth(String format) {
        String strDate = null;/* w  w  w  .j a va 2 s  . c  o m*/
        try {
            Calendar c = new GregorianCalendar();
            SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(
                    format);
            // ???????????
            c.set(Calendar.DATE, 1);
            c.roll(Calendar.DATE, -1);
            strDate = mSimpleDateFormat.format(c.getTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return strDate;
    }
}

Related Tutorials