1
1
.
package
com.sunney.test;
2 2 .
3 3 . import java.text.ParsePosition;
4 4 . import java.text.SimpleDateFormat;
5 5 . import java.util.Calendar;
6 6 . import java.util.Date;
7 7 . import java.util.GregorianCalendar;
8 8 .
9 9 . public class mynew {
10 10 .
11 11 . public static void main(String[] args) {
12 12 .
13 13 . System.out.println( " 日期增加一天= " + addDay( " 2007-10-10 " , 1 ));
14 14 .
15 15 . }
16 16 .
17 17 . public static String addDay(String s, int n) {
18 18 . try {
19 19 . SimpleDateFormat sdf = new SimpleDateFormat( " yyyy-MM-dd " );
20 20 .
21 21 . Calendar cd = Calendar.getInstance();
22 22 . cd.setTime(sdf.parse(s));
23 23 . cd.add(Calendar.DATE, n); // 增加一天
24 24 . // cd.add(Calendar.MONTH, n); // 增加一个月
25 25 .
26 26 . return sdf.format(cd.getTime());
27 27 .
28 28 . } catch (Exception e) {
29 29 . return null ;
30 30 . }
31 31 .
32 32 . }
33 33 . }
34
2 2 .
3 3 . import java.text.ParsePosition;
4 4 . import java.text.SimpleDateFormat;
5 5 . import java.util.Calendar;
6 6 . import java.util.Date;
7 7 . import java.util.GregorianCalendar;
8 8 .
9 9 . public class mynew {
10 10 .
11 11 . public static void main(String[] args) {
12 12 .
13 13 . System.out.println( " 日期增加一天= " + addDay( " 2007-10-10 " , 1 ));
14 14 .
15 15 . }
16 16 .
17 17 . public static String addDay(String s, int n) {
18 18 . try {
19 19 . SimpleDateFormat sdf = new SimpleDateFormat( " yyyy-MM-dd " );
20 20 .
21 21 . Calendar cd = Calendar.getInstance();
22 22 . cd.setTime(sdf.parse(s));
23 23 . cd.add(Calendar.DATE, n); // 增加一天
24 24 . // cd.add(Calendar.MONTH, n); // 增加一个月
25 25 .
26 26 . return sdf.format(cd.getTime());
27 27 .
28 28 . } catch (Exception e) {
29 29 . return null ;
30 30 . }
31 31 .
32 32 . }
33 33 . }
34