[Q#22195093][A#22195142] Android how to get tomorrow's date
https://stackoverflow.com/q/22195093
In my android application. I need to display tomorrow's date, for example today is 5th March so I need to display as 6 March. I know the code for getting today's date, month and year. date calculating If I have the code will it display tomorrow's date. or just add one to today's date? For example, if today is January 31. With the above code, will it display like 1 or 32? If it displays 32, what change I need to make?
Answer
https://stackoverflow.com/a/22195142
Get today's date as a Calendar. Add 1 day to it. Format for display purposes. For example,
APIzation
GregorianCalendar gc = new GregorianCalendar();
gc.add(Calendar.DATE, 1);
// now do something with the calendar
package com.stackoverflow.api;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class Human22195142 {
public static Date getTomorrowDate() {
GregorianCalendar gc = new GregorianCalendar();
gc.add(Calendar.DATE, 1);
return gc.getTime();
}
}
package com.stackoverflow.api;
import java.util.Calendar;
import java.util.GregorianCalendar;
/**
* Android how to get tomorrow's date
*
* @author APIzator
* @see <a href="https://stackoverflow.com/a/22195142">https://stackoverflow.com/a/22195142</a>
*/
public class APIzator22195142 {
public static void android() throws Exception {
GregorianCalendar gc = new GregorianCalendar();
gc.add(Calendar.DATE, 1);
// now do something with the calendar
}
}