特定日期后第一个获得周一?定日、第一个、期后

2023-09-04 09:44:32 作者:等在十字路口

如果我的应用程序收到了一定的日期,我怎么能找到第一个在下周一的日期吗?

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.