Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add days into the date in android

Tags:

date

android

In my database I am getting start date like 2011-11-30(yyyy/mm/dd)format.and duration date like 40 days.How can i calculate the days and get new date format of mm/dd/yyyy.

Can anyone help me

Thanks

like image 787
user1061793 Avatar asked Jan 05 '12 06:01

user1061793


People also ask

How do I add 7 days to Java Util date?

Adding Days to the given Date using Calendar class Add the given date to the calendar by using setTime() method of calendar class. Use the add() method of the calendar class to add days to the date. The add method() takes two parameter, i.e., calendar field and amount of time that needs to be added.

How do I change the date format on my Android calendar?

Calendar calendar = Calendar. getInstance(); SimpleDateFormat format = new SimpleDateFormat("EEEE, MMMM d, yyyy 'at' h:mm a"); System. out. println(format.

How can I get tomorrow date in Android?

get(Calendar. DAY_OF_MONTH) + 1; will it display tomorrow's date. or just add one to today's date? For example, if today is January 31.


1 Answers

You can try something like this,

String dt = "2012-01-04";  // Start date SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar c = Calendar.getInstance(); try {     c.setTime(sdf.parse(dt)); } catch (ParseException e) {     e.printStackTrace(); } c.add(Calendar.DATE, 40);  // number of days to add, can also use Calendar.DAY_OF_MONTH in place of Calendar.DATE SimpleDateFormat sdf1 = new SimpleDateFormat("MM-dd-yyyy"); String output = sdf1.format(c.getTime());  
like image 133
Lalit Poptani Avatar answered Sep 28 '22 10:09

Lalit Poptani