如何在Java中增加一天的日期? [英] How can I increment a date by one day in Java?

查看:86
本文介绍了如何在Java中增加一天的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以yyyy-mm-dd的格式取得日期。我需要增加一天。如何做到这一点?

I am getting date in the format as yyyy-mm-dd. I need to increment this by one day. How can I do this?

推荐答案

这样的事情应该是诀窍:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆