get Month From Resource - Android java.util

Android examples for java.util:Month

Description

get Month From Resource

Demo Code


import android.content.Context;
import java.util.Calendar;
import java.util.Date;

public class Main{
    public static String getMonthFromResource(Date date, Context context) {
        String resourceName = context.getPackageName() + ":string/month_"
                + CalendarHelper.getMonth(date);
        int resourceId = context.getResources().getIdentifier(resourceName,
                null, null);//from   w  ww. ja  v a 2 s. c  om

        return context.getResources().getString(resourceId);
    }
    public static int getMonth(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(Calendar.MONTH) + 1;
    }
}

Related Tutorials