怎么给java Date类型字段加一天代码?
String startdate=UIDBComboBox1.getValue();
startdate是日期字断,求java Date类型字段加一天代码 展开
String startdate=UIDBComboBox1.getValue();
Date date = (new SimpleDateFormat("yyyy-MM-dd")).parse(startdate);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DATE,1);
date =cal.getTime();
startdate = (new SimpleDateFormat("yyyy-MM-dd")).format(date);
举例:
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class $ {
public static void main(String[] args) {
Format f = new SimpleDateFormat("yyyy-MM-dd");
Date today = new Date();
System.out.println("今天是:" + f.format(today));
Calendar c = Calendar.getInstance();
c.setTime(today);
c.add(Calendar.DAY_OF_MONTH, 1);// 今天+1天
Date tomorrow = c.getTime();
System.out.println("明天是:" + f.format(tomorrow));
}
}
结果:
今天是:2013-10-09
明天是:2013-10-10