如何在 Java 中将日期增加一天? [英] How can I increment a date by one day in Java?
本文介绍了如何在 Java 中将日期增加一天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用这种格式的日期:yyyy-mm-dd
.
I'm working with a date in this format: yyyy-mm-dd
.
如何将此日期增加一天?
How can I increment this date by one day?
推荐答案
这样的事情应该可以解决问题:
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
这篇关于如何在 Java 中将日期增加一天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文