开发者

How to add 15 days in String Date in android

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜