I have a probl开发者_Python百科em that I want to add 15 days in my date string but I don't know How to do that? Please help me regarding that.
Thanks in advance
You must parse the date by means of a DateFormat, then use a GregorianCalendar to do the maths:
Date date = DateFormat.getDateFormat(this).parse("12/31/1999");
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(date);
gc.add(Calendar.DAY_OF_MONTH, 15);
You can use the add method. Create a calendar object with the current date. And use the below method.
This should give you an idea
DateFormat objFormatter = new SimpleDateFormat("dd-MM-yyyy");
objCalendar.add(Calendar.DATE, 15);
return objFormatter.format(objCalendarDup.getTime());
Turn it into a java.util.Date
and then use either java.util.Calendar
or JODA time to do i
it.
A Date isn't a String. Use the types that are available to you. Convert the String into a Date using java.text.DateFormat
.
精彩评论