Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of Calender.LONG in getDisplayNames() unresolved

I am trying to use getDisplayNames() on a Calendar object in my Android code. I have java.util.Calendar included and haven't had any troubles using any other public members of the Calendar class (i.e. Calendar.MONTH). Now I am attempting the following line...

mReminderCal.getDisplayName(Calendar.DAY_OF_MONTH, Calendar.LONG, Locale.US)

And Eclipse is telling me Calendar.LONG or Calendar.SHORT don't exist.

According to the documentation here they should exist: http://developer.android.com/reference/java/util/Calendar.html#LONG

Any insight?

like image 917
Will Tate Avatar asked Jan 31 '11 18:01

Will Tate


2 Answers

Try This (same for Gregorian or regular calendar). DateFormatSymbols is API level 1.

int month = date.get(GregorianCalendar.MONTH);  
String monthName = new DateFormatSymbols().getMonths()[month];
like image 158
ProjectJourneyman Avatar answered Sep 18 '22 13:09

ProjectJourneyman


I found the issue.

The getDisplayName() and associated Calendar.LONG and Calendar.SHORT are API level 9 only. I'm on API level 4 for backwards compatibility. I suppose, I will have to create my own function to translate the month enums into strings.

like image 25
Will Tate Avatar answered Sep 19 '22 13:09

Will Tate