edi233
edi233

Reputation: 3031

Calendar current day in android

i use calendar object to dates. I set calendar in this way:

Calendar mCalendar = Calendar.getInstance();
mCalendar.add(Calendar.YEAR, 1980);
mCalendar.add(Calendar.MONTH, 1);
mCalendar.add(Calendar.DAY_OF_MONTH, 1);                 
int daysRange = (2050-1980)*365;

ArrayList<String> allDays = new ArrayList<String>();
SimpleDateFormat mFormat = new SimpleDateFormat("EEE, dd MMM", Locale.US);
for(int i = 0; i < daysRange; i++){
    allDays.add(mFormat.format(mCalendar.getTime()));
    mCalendar.add(Calendar.DAY_OF_MONTH, 1);
}

now I want to set up current day in calendar. How can I do that?

edit: As you can see I add dates to Arraylist. Dates between 2980 to 2050. Now I want to get from this array date which is current day. So I need to get int number of element which is in my Array current day: 27.12.2013

Upvotes: 0

Views: 98

Answers (1)

Tabrej Khan
Tabrej Khan

Reputation: 894

Here is a solution but time complexity is not optimal one:

Date date = new Date();
for(int i=0; i<allDays.size();i++) {
    if(allDays.get(i).getTimeInMillis() == date.getTime()) {
        break;
    }

    //return i is the index you are searching for.
}

Upvotes: 3

Related Questions