你可以这样做更简单,看看Date类:
http://developer.android.com/reference/java/util/Date.html
,并尝试像,伪:
// This month 5th
Date date = new Date();
date.setDay(5);
// Next month the 5th
Date nextDate = new Date();
nextDate.setDay(5);
nextDate.setMonth(date.getMonth()+1);
您将有问题,当你来到今年底,但它比你目前所面对的问题少。
还有其他Date API,有些会为您解决年度问题。只是看看周围。
编辑
只注意到弃用使用日历:
http://developer.android.com/reference/java/util/Calendar.html
Calendar now = Calendar.getInstance();
now.setField(Calendar.DAY_OF_MONTH, 5);
// Next month the 5th
Calendar nextDate = new = Calendar.getInstance();
nextDate.setField(Calendar.DAY_OF_MONTH, 5);
nextDate.setField(Calendar.MONTH_OF_YEAR, date.getField(Calendar.MONTH_OF_YEAR)+1); // issues in december
'Calendar'比'Date'一个更好的选择。 – CommonsWare 2011-03-31 15:23:04
@CommonsWare我正在编辑,因为你评论:-)通常在Java中使用DateMidnight(),因为它有加号(持续时间);考虑数月和数年,有什么建议? – Blundell 2011-03-31 15:26:11
没关系应该做的第一个开始日期。现在我只需要重复一点。 – AndyAndroid 2011-03-31 15:34:47