如何添加7天当前的日期,而不会超过一个月的可用天数? [英] How to add 7 days to current date while not going over available days of a month?

查看:280
本文介绍了如何添加7天当前的日期,而不会超过一个月的可用天数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让该月的今天一天。

和我想要做的就是增加7天数和获得一个月,目前一天。

此外,我希望它能够进入下一个month..Lets说今天是第29届。当它增加了7天,我该怎么去走接下来的一个月,如29 + 7就等于下个月的5日。

如何,我会去这样做?

香港专业教育学院已设法获取当前日期。

 日历CAL = Calendar.getInstance();
    INT天= cal.get(Calendar.DAY_OF_MONTH);
    INT DAYOFMONTH =天;
    今天的String = getToday();
 

我使用的这个,因为我想推出一个AsyncTask的在我的主要活动,每7天。

解决方案

 添加(Calendar.DAY_OF_MONTH,7);
 

日历的JavaDoc

I am trying to get todays day of the month.

And what i want to do is add seven days to the number and the get that current day of the month.

Also i want it to be able to go to the next month..Lets say today is the 29th. When it adds 7 days how can i get it to go the the next month such as 29 + 7 would equal the 5th of the next month.

How would i go about doing this?

Ive already managed to get the current date.

Calendar cal = Calendar.getInstance();
    int day = cal.get(Calendar.DAY_OF_MONTH);
    int dayOfMonth = day;
    String today = getToday();

I am using this because i would like to launch an asynctask in my main activity every 7 days.

解决方案

add(Calendar.DAY_OF_MONTH, 7);

From Calendar JavaDoc

这篇关于如何添加7天当前的日期,而不会超过一个月的可用天数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆