开发者

Add date by one

hii all I have date in string 开发者_JAVA技巧form I want to convert it into first date form and increase date to one like

12-12-2000

to

13-12-2000

and want to re convert that increased date to string


I think this will work

String date = "2011-05-01"; 
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.setTime(df.parse(date));
c.add(Calendar.DATE, 1);  // how many days you want to add like here 1
String addeddate = df.format(c.getTime());  


  1. DateFormat for parsing and formatting. Example
  2. Calendar.roll(...) for date arithmetic. Example

NOTE: Do not forget setLenient(true). Example

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜