get Day from date string - Android java.util

Android examples for java.util:Day

Description

get Day from date string

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 int getDay(String strDate, String format) {
        int day = 0;
        try {/*from   w w w . ja va2  s  . c  o  m*/
            Calendar c = new GregorianCalendar();
            SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(
                    format);
            c.setTime(mSimpleDateFormat.parse(strDate));
            day = c.get(Calendar.DAY_OF_MONTH);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return day;
    }

}

Related Tutorials