I want to get the day of the week for a number of dates saved in a database.
try {
ResultSet rs = DBHelper.st.executeQuery("SELECT date FROM days ORDER BY date ASC;");
while (rs.next()) {
Calendar c = Calendar.getInstance();
c.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(rs.getString(1)));
String d = new SimpleDateFormat("EE").format(c.get(Calendar.DAY_OF_WEEK));
System.out.println(d + ", " rs.getString(1).substring(8));
}
} catch(SQLException xc) {xc.printStackTrace();}
I am generating a new Calendar Instance for every row of the ResultSet but somehow the weekday parsed is the same for every date. The Calendar always gives back the day of the week which matches the first date in the list.
e.g.
Tue, 05 |
Tue, 06
...
I am guessing that the Calendar Instance stays the same for all rows. Can someone suggest a way to make sure that Calendar c is updated for every row? My approach does not seem to cut it.