Theo Theo - 4 months ago 7x
Java Question

SimpleDateFormat and Date object

In my android app I retrieve from an api the current day as.

long dateTime = innerJSON.getLong("dt");

Date weekDay = new Date(dateTime * 1000L);

SimpleDateFormat outFormat = new
String day = outFormat.format(weekDay);

And I get the current day ie Monday.

For the date I use the same Date object but with a different SimpleDateFormat object.

SimpleDateFormat outFormat1 = new SimpleDateFormat("dd-M-yyyy");
String date = outFormat1.format(weekDay);

And that gives me,


which is fine. However, I want the date to have a format of

28 May

Any ideas on that? I checked the official orarcle's site,but I can't find a solution.




Try this

SimpleDateFormat outFormat1 = new SimpleDateFormat("dd MMM");

you will get the output you required.