开发者

Add date by one

开发者 https://www.devze.com 2023-02-06 03:25 出处:网络
hii all I have date in string 开发者_JAVA技巧form I want to convert it into first date form and increase date to one like

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

精彩评论

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