Java Calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY), will it roll backwards, forwards or unknow

Posted by Will on Stack Overflow See other posts from Stack Overflow or by Will
Published on 2009-08-23T20:30:03Z Indexed on 2010/03/09 8:21 UTC
Read the original article Hit count: 520

Filed under:
|

Suppose the following code is executed on the 22nd of August 2009 (a Saturday)

   Calendar c = Calendar.getInstance();
   c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);

c.get(Calendar.DAY_OF_MONTH) will return 23. I'm interested in the conditions is would return 14 (last Sunday, rather than the next Sunday).

Are there any rules associated with the direction Calendar will roll the DAY_OF_MONTH/YEAR when DAY_OF_WEEK is set? If so what are they?

© Stack Overflow or respective owner

Related posts about java

Related posts about calendar