Theo Theo - 2 years ago 78
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.



Answer Source

Try this

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

you will get the output you required.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download