java 给当前时间加上天数
public class MyRestAreaTest {
public static void main ( String[ ] args) {
Date d = new Date ( ) ;
SimpleDateFormat format = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss" ) ;
String currdate = format. format ( d) ;
System. out. println ( "现在的日期是:" + currdate) ;
Calendar ca = Calendar. getInstance ( ) ;
ca. add ( Calendar. DATE, 3 ) ;
d = ca. getTime ( ) ;
String enddate = format. format ( d) ;
System. out. println ( "增加天数以后的日期:" + enddate) ;
}
}
输出结果:
Java 给定一个指定日期 加上天数 输出加上天数的日期
public class MyRestAreaTest2 {
public static void main ( String[ ] args) {
String createDate = "2000-01-01 09:20:25" ;
System. out. println ( "指定的日期为:" + createDate) ;
SimpleDateFormat sdf = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss" ) ;
int day = 5 ;
try {
Date date = sdf. parse ( createDate) ;
Calendar cl = Calendar. getInstance ( ) ;
cl. setTime ( date) ;
cl. add ( Calendar. DATE, day) ;
String temp = "" ;
temp = sdf. format ( cl. getTime ( ) ) ;
System. out. println ( "加上天数的日期:" + temp) ;
} catch ( ParseException e) {
e. printStackTrace ( ) ;
}
}
}
输出结果为