Question

I have the following code:

Log.e("year = ",eventiCompleti.get(i).year);
Log.e("month = ",eventiCompleti.get(i).month);
Log.e("day = ",eventiCompleti.get(i).day);
Log.e("hour = ",eventiCompleti.get(i).hour);

TimeZone MyTimezone = TimeZone.getDefault();
Calendar calendar = new GregorianCalendar(MyTimezone);                              
calendar.set(Integer.parseInt(eventiCompleti.get(i).year),Integer.parseInt( eventiCompleti.get(i).month),Integer.parseInt( eventiCompleti.get(i).day),0,0,0);
String month_name=calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault());//Locale.US);
String day_name=calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault());

Log.e("day of the week = ",day_name);

Well, this is the Output:

06-30 21:33:55.828: E/year =(11254): 2013
06-30 21:33:55.828: E/month =(11254): 08
06-30 21:33:55.828: E/day =(11254): 07
06-30 21:33:55.828: E/hour =(11254): 18:00
06-30 21:33:55.828: E/day of the week =(11254): Saturday

Obviously, August 7th 2013 in NOT a Saturday.

Please what am I doing wrong???

Thanks!!!

Was it helpful?

Solution

You assume that month starts on 1. It doesn't. In Calendar it starts with January=0.

So change your code to:

eventiCompleti.get(i).month-1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top