Reputation: 1049
I have this code
String date = "18/06/2014";
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Calendar c = Calendar.getInstance();
c.setTime(sdf.parse(date));
c.add(Calendar.DATE, +2);
I'm trying to get formatted date object from calendar object but without any success. Do you have any suggestion?
Upvotes: 1
Views: 788
Reputation: 201447
Date
is an object, it doesn't have an inherent textual representation. The SimpleDateFormat
class can be used to provide the textual representation you're looking for,
String date = "30/06/2014";
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Calendar c = Calendar.getInstance();
c.setTime(sdf.parse(date));
c.add(Calendar.DATE, +2);
System.out.println(sdf.format(c.getTime()));
Will output
02/07/2014
Upvotes: 2