Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 每周或每月更改日期_Java_Android_Calendar - Fatal编程技术网

Java 每周或每月更改日期

Java 每周或每月更改日期,java,android,calendar,Java,Android,Calendar,我正在做一个日历项目,我想知道在android的类Calendar中是否有任何内置函数可以每天或每周更改 例如,我将数据存储在今天的日期中。我想每天或每周重复这个操作。 我不想使用日历api e、 g 假设我的日历实例变量存储日期“2014-26-01” 所以我想做一些类似的事情 final Calendar c = Calendar.getInstance(); for(int i = o ; i <= 30 ; i++){ yy = c.get(Calendar.YEAR

我正在做一个日历项目,我想知道在android的类
Calendar
中是否有任何内置函数可以每天或每周更改

例如,我将数据存储在今天的日期中。我想每天或每周重复这个操作。 我不想使用日历api

e、 g

假设我的日历实例变量存储日期“2014-26-01”

所以我想做一些类似的事情

final Calendar c = Calendar.getInstance();

for(int i = o ; i <= 30 ; i++){


    yy = c.get(Calendar.YEAR);
    mm = c.get(Calendar.MONTH);
    dd = c.get(Calendar.DAY_OF_MONTH);

    Toast.makeText(this,yy+"-"+mm+"-"+dd,Toast.LENGH_SHORT).show();
    /** here i want to change the value of `Calendar c` to next day or next week**/
}
final Calendar c=Calendar.getInstance();

对于(int i=o;i,可以使用calendar.add()方法增加或减少日期。 例如:

公共无效日历getTomorrow(){

}

公众假期{

}

顺便说一句,图书馆提供了方便的
plusDays
plusWeeks
plusMonths
计算方法

//java.util.Date dateNow=new java.util.Date();
//将java.util.Date转换为Joda时间。只需将日期传递给构造函数。
//DateTime now=新的DateTime(dateNow,DateTimeZone.forID(“欧洲/巴黎”);
DateTime now=新的日期时间(DateTimeZone.forID(“欧洲/巴黎”);
DateTime明天=现在。星期四(1);
DateTime nextWeek=now.plusweek(1);
DateTime firstMomentOfNextWeek=now.plusWeeks(1).withTimeAtStartOfDay();
DateTime nextMonth=now.plusMonths(1);
//将Joda Time转换回过时的捆绑Java类Java.util.Date。
java.util.Date dateNow=now.toDate();
转储到控制台

System.out.println(“now:+now”);
System.out.println(“现在使用UTC/GMT:+now.toDateTime(DateTimeZone.UTC));
System.out.println(“明天:+明天);
System.out.println(“nextWeek:+nextWeek”);
System.out.println(“firstmomentfnextweek:+firstmomentfnextweek”);
System.out.println(“下一个月:+nextMonth”);
System.out.println(“dateNow:+dateNow);//记住,j.u.Date是存在的。“toString”应用默认时区,但实际上日期没有时区。
当运行时

现在:2014-01-27T00:06:41.982+01:00
现在使用UTC/GMT:2014-01-26T23:06:41.982Z
明天:2014-01-28:00:06:41.982+01:00
下一周:2014-02-03T00:06:41.982+01:00
下周第一个重要时刻:2014-02-03T00:00:00.000+01:00
下个月:2014-02-27T00:06:41.982+01:00
日期:2014年1月26日星期日15:06:41太平洋标准时间

解释了
日历
可以为您做什么。@ABoschman请检查我更新的问题。Thanx@zapl是的,我已经检查过了,但是找不到解决方案。听起来好像有一种方法可以
添加
一些东西。@zapl我以前已经试过了,但是让我再试一次:)我会告诉你的
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE,1);

//return the calendar with the date of tomorrow
return calendar;
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE,-1);

//return the calendar with the date of yesterday
return calendar;