如果我的应用程序收到了一定的日期,我怎么能找到第一个在下周一的日期吗?
If my app received a certain date, how can I find out the date of first next Monday?
例如,我得到的日期2011年09月28,我要找出第一个星期一此日期后的日期。
For example, I get the date 28 Sep 2011 and I have to find out the date of the first Monday after this date.
这样做:
GregorianCalendar date = new GregorianCalendar( year, month, day );
while( date.get( Calendar.DAY_OF_WEEK ) != Calendar.MONDAY )
date.add( Calendar.DATE, 1 );
您现在可以提取年,日和月的日期。记住那个月第一个值为0(例如,元月= 0,Febuary = 1等),天不是
You can now extract the year, day and month from date. Remember that month is 0 based (e.g. January = 0, Febuary = 1, etc.) and day is not.