I need to print date like today,Yesterday,2 days ago like that for that i have done
I am getting date like : String date1 = \"Thu Nov 13 19:01:25 GMT+05:30 2014\";
In you DateTimeFormatter, it expects a Date in a certain format, i.e. "EEE hh:mma MMM d, yyyy"
:
DateTime dateTime = DateTimeFormat.forPattern("EEE hh:mma MMM d, yyyy")
.parseDateTime(date);
But what you pass, is of format "MM/dd/yyyy"
:
SimpleDateFormat outputFormat1 = new SimpleDateFormat("MM/dd/yyyy");
op = outputFormat1.format(d);
op = formatToYesterdayOrToday(op);
So, what you could do is to change your DateTimeFormatter to expect you initial format "MM/dd/yyyy"
:
DateTime dateTime = DateTimeFormat.forPattern("MM/dd/yyyy")
.parseDateTime(date);
This should solve the error that you get. I don't know if the whole thing in the end gives you what you want ("today", "yesterday", "2 days ago", ...).