get Month value from Date value - Android java.util

Android examples for java.util:Month

Description

get Month value from Date value

Demo Code

import android.annotation.SuppressLint;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class Main{

    public static int getMonth(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);// w ww  .  j a  va 2 s  .c  o m
        return c.get(Calendar.MONTH) + 1;

    }
    public static String getMonth(Date date, Locale locale) {
        SimpleDateFormat sdf = new SimpleDateFormat("MMM", locale);
        return sdf.format(date);

    }

}

Related Tutorials