Given a String that is simply a day, for example, “Thu” or “Thursday”, how would I get a java.util.Calendar object where the day String represents the closest String to today. In other words, today is Monday, 3/26/29012, so if the String were “Thu”, I would want to form a date that represents “3/29/2012”. If the String passed in is “Mon” and we’re on Monday, I would want today’s date. In this example, “3/26/2012”.
I tried this …
final DateFormat formatter = new SimpleDateFormat("EEE");
java.util.Date date = (Date) formatter.parse(dayOfWeekStr);
final Calendar now = Calendar.getInstance();
dateCal.set(Calendar.YEAR, now.get(Calendar.YEAR));
dateCal.set(Calendar.MONTH, now.get(Calendar.MONTH));
dateCal.setTime(date);
but it isn’t working. Once I set the date, the year and month results to 1970, January.
I ended up going with
If anyone has a more concise solution, I’ll accept that instead.