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,092
  • 6
  • 40
  • 63

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,102
  • 2
  • 24
  • 33
Antoniossss
  • 28,922
  • 5
  • 49
  • 91
4

Use Calendar add method.

    Calendar cal=Calendar.getInstance();
    cal.add(Calendar.DATE, 1);
Masudul
  • 21,543
  • 5
  • 40
  • 55
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.
  • 87,500
  • 20
  • 164
  • 172