I’m trying to convert SimpleDateFormat to String, but result is not correct.
Calendar cal = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Log.d("current date",dateFormat.format(cal.getTime()));
cal.add(Calendar.YEAR,-3);
Log.d("3 years previous date",dateFormat.format(cal.getTime()));
String valnow = dateFormat.format(new Date());
Output:
01-19 05:34:52.148: DEBUG/current date(556): 19/01/2012
01-19 05:34:52.148: DEBUG/3 years previous date(556): 19/01/2009
But valnow value = 19/01/2012.
Could someone please tell me the way to do this? If you have any worked through examples, that would be a real help!
Try replacing
with