get First Day Of Month and return java.util.Date - Android java.util

Android examples for java.util:Day

Description

get First Day Of Month and return java.util.Date

Demo Code

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 Date getFirstDayOfMonth(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);/*from   ww  w .  j a  v  a 2 s . c o m*/

        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH);

        return new GregorianCalendar(year, month, 1, 0, 0, 0).getTime();
    }

}

Related Tutorials