get First Day Of Month by format - Android java.util

Android examples for java.util:Day

Description

get First Day Of Month by format

Demo Code

import android.text.TextUtils;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main{

    public static String getFirstDayOfMonth(String format) {
        String strDate = null;/* w  ww .jav a 2 s .c  o m*/
        try {
            Calendar c = new GregorianCalendar();
            SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(
                    format);
            //???????
            c.set(GregorianCalendar.DAY_OF_MONTH, 1);
            strDate = mSimpleDateFormat.format(c.getTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return strDate;

    }

}

Related Tutorials