Set Calendar to X Day in Month
<p>I am trying to get a time down to the minute from a Calendar object built from four inputs: occurrence in month (3rd), day (Thursday), hour (1), minute(30), and am/pm. Also, if the time is in the past the month should increase by one.</p>

<p>How do I set a a Calendar to this time?</p>

<p>This code seems to not set the day.  The hour, minute, and am/pm are setting correctly though.  </p>

<p>Calendar Setup:</p>

<pre><code>long getTime() {
    Calendar calendar = Calendar.getInstance();

    calendar.set(Calendar.DAY_OF_WEEK_IN_MONTH, getDayOfWeekInMonth());
    calendar.set(Calendar.DAY_OF_WEEK, getDayOfWeek());
    calendar.set(Calendar.HOUR, getHour());
    calendar.set(Calendar.MINUTE, getMinute());
    calendar.set(Calendar.AM_PM, getAmPm());

    if (System.currentTimeMillis() &gt; calendar.getTimeInMillis()) {
        calendar.add(Calendar.MONTH, 1);
    }

    return calendar.getTimeInMillis();

}

int getDayOfWeekInMonth() {
    return weekOfMonthSpinner.getSelectedItemPosition() + 1;
}

int getDayOfWeek() {
    switch(dayOfWeekSpinner.getSelectedItemPosition()) {
    case 0:
        return Calendar.SUNDAY;
    case 1:
        return Calendar.MONDAY;
    case 2:
        return Calendar.TUESDAY;
    case 3:
        return Calendar.WEDNESDAY;
    case 4:
        return Calendar.THURSDAY;
    case 5:
        return Calendar.FRIDAY;
    case 6:
        return Calendar.SATURDAY;
    default:
        return 0;
    }
}

int getHour() {
    return Integer.parseInt((String) hourSpinner.getSelectedItem());
}

int getMinute() {
    return Integer.parseInt((String) minuteSpinner.getSelectedItem());
}

int getAmPm() {
    switch(amPmSpinner.getSelectedItemPosition()) {
    case 0:
        return Calendar.AM;
    case 1:
        return Calendar.PM;
    default:
        return 0;
    }
}
</code></pre>

<p>Spinner Setup:</p>

<pre><code>&lt;string-array name="week_of_month"&gt;
    &lt;item&gt;1st&lt;/item&gt;
    &lt;item&gt;2nd&lt;/item&gt;
    &lt;item&gt;3rd&lt;/item&gt;
    &lt;item&gt;4th&lt;/item&gt;
 &lt;/string-array&gt;
&lt;string-array name="day_of_week"&gt;
    &lt;item&gt;Sunday&lt;/item&gt;
    &lt;item&gt;Monday&lt;/item&gt;
    &lt;item&gt;Tuesday&lt;/item&gt;
    &lt;item&gt;Wednesday&lt;/item&gt;
    &lt;item&gt;Thursday&lt;/item&gt;
    &lt;item&gt;Friday&lt;/item&gt;
    &lt;item&gt;Saturday&lt;/item&gt;
&lt;/string-array&gt;
&lt;string-array name="hour"&gt;
    &lt;item&gt;1&lt;/item&gt;
    &lt;item&gt;2&lt;/item&gt;
    &lt;item&gt;3&lt;/item&gt;
    &lt;item&gt;4&lt;/item&gt;
    &lt;item&gt;5&lt;/item&gt;
    &lt;item&gt;6&lt;/item&gt;
    &lt;item&gt;7&lt;/item&gt;
    &lt;item&gt;8&lt;/item&gt;
    &lt;item&gt;9&lt;/item&gt;
    &lt;item&gt;10&lt;/item&gt;
    &lt;item&gt;11&lt;/item&gt;
    &lt;item&gt;12&lt;/item&gt;
&lt;/string-array&gt;
&lt;string-array name="minute"&gt;
    &lt;item&gt;00&lt;/item&gt;
    &lt;item&gt;05&lt;/item&gt;
    &lt;item&gt;10&lt;/item&gt;
    &lt;item&gt;15&lt;/item&gt;
    &lt;item&gt;20&lt;/item&gt;
    &lt;item&gt;25&lt;/item&gt;
    &lt;item&gt;30&lt;/item&gt;
    &lt;item&gt;35&lt;/item&gt;
    &lt;item&gt;40&lt;/item&gt;
    &lt;item&gt;45&lt;/item&gt;
    &lt;item&gt;50&lt;/item&gt;
    &lt;item&gt;55&lt;/item&gt;
&lt;/string-array&gt;
&lt;string-array name="am_pm"&gt;
    &lt;item&gt;am&lt;/item&gt;
    &lt;item&gt;pm&lt;/item&gt;
&lt;/string-array&gt;

adapter = ArrayAdapter.createFromResource(getActivity(), R.array.week_of_month, R.layout.spinner_item);
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
weekOfMonthSpinner.setAdapter(adapter);

adapter = ArrayAdapter.createFromResource(getActivity(), R.array.day_of_week, R.layout.spinner_item);
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
dayOfWeekSpinner.setAdapter(adapter);

adapter = ArrayAdapter.createFromResource(getActivity(), R.array.hour, R.layout.spinner_item);
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
hourSpinner.setAdapter(adapter);

adapter = ArrayAdapter.createFromResource(getActivity(), R.array.minute, R.layout.spinner_item);
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
minuteSpinner.setAdapter(adapter);

adapter = ArrayAdapter.createFromResource(getActivity(), R.array.am_pm, R.layout.spinner_item);
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
amPmSpinner.setAdapter(adapter);
</code></pre>
