Shakeeb Ayaz
Shakeeb Ayaz

Reputation: 6096

How to Increase the date by one

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

Upvotes: 4

Views: 611

Answers (3)

Alexis C.
Alexis C.

Reputation: 93842

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

Upvotes: 1

Antoniossss
Antoniossss

Reputation: 32517

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

Upvotes: 9

Masudul
Masudul

Reputation: 21961

Use Calendar add method.

    Calendar cal=Calendar.getInstance();
    cal.add(Calendar.DATE, 1);

Upvotes: 4

Related Questions