Theo Theo - 6 months ago 10
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
SimpleDateFormat("EEEE");
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,

28-5-2016


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.

Thanks,

Theo.

Answer

Try this

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

you will get the output you required.

Comments