Basics :: java: Date addition. Is it easier to use Calendar for java to add dates? There is also a new DateTime in php (also in java).
demojava/demo16/Demo16.java
package demojava.demo16;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class Demo16 {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
Date now = new Date();
SimpleDateFormat sm = new SimpleDateFormat("yyyy/MM/dd");
System.out.println(sm.format(now));
for(int i = 0 ;i <= 31; i++){
cal.add(Calendar.DAY_OF_MONTH,1);
System.out.println(sm.format(cal.getTime()));
}
}
}
Execution result
Recommended Posts