S
S
Shohrukh Alimov2017-04-07 10:03:21
Android
Shohrukh Alimov, 2017-04-07 10:03:21

How to add 1 day correctly?

I am using Wdullaer Materialdatetimepicker library for date picker. And when adding 1st day (if the number is 31) then it shows 32. Here is how I add one day:

Integer.toString(++dayOfMonth) + "/" + monthOfYear + "/" + Integer.toString(year);

How can I make it show the 1st of the next month instead of the 32nd?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Myvrenik, 2017-04-07
@AlimNinja

Use Calendar to store the date. There are operations that you need.

Calendar calendar = new GregorianCalendar(year, monthOfYear, dayOfMonth);
calendar.add(Calendar.DATE, 1);

And I don’t advise you to do it , there is DateFormat for the date format , you can use it to format it into a locale-dependent format. day + "/" + month + "/" + year

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question