且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Java中增加一天的日期?

更新时间:2021-11-11 08:48:24

这样的事情应该是诀窍:

Something like this should do the trick:

String dt = "2008-01-01";  // Start date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.setTime(sdf.parse(dt));
c.add(Calendar.DATE, 1);  // number of days to add
dt = sdf.format(c.getTime());  // dt is now the new date