4

I have date and time in the format of yyyy-MM-dd:HH:mm I want to increase the dd by one i.e 2013-10-24:11:20 to 2013-10-25:11:20

    SimpleDateFormat mSDF = new SimpleDateFormat("yyyy-MM-dd:HH:mm");
    time = mSDF.format(calSet.getTime());//calset in my calendar instance 

I don't know what exactly my time/date is .I only know that I have to increase date by one for time variable

Shakeeb Ayaz
  • 6,200
  • 6
  • 45
  • 64

3 Answers3

9

Use calendar

Calendar cal=Calendar.getInstance();
cal.setDate(yourdate); // pass parsed Date object
cal.add(Calendar.DATE, 1);
cal.getTime(); // here you will get your date
newuser
  • 8,338
  • 2
  • 25
  • 33
Antoniossss
  • 31,590
  • 6
  • 57
  • 99
4

Use Calendar add method.

    Calendar cal=Calendar.getInstance();
    cal.add(Calendar.DATE, 1);
Masudul
  • 21,823
  • 5
  • 43
  • 58
1

You can also use the set method :

c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH)+1);

Output :

2012-12-31:10:25
2013-01-01:10:25
Alexis C.
  • 91,686
  • 21
  • 171
  • 177