-3

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.

Theo
  • 3,099
  • 12
  • 53
  • 94

3 Answers3

3

You need to use dd MMM format here.

More details provided here in official documentation.

SimpleDateFormat outFormat1 = new SimpleDateFormat("dd MMM");
String date = outFormat1.format(weekDay);
Alex Chengalan
  • 8,211
  • 4
  • 42
  • 56
3

Try this

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

you will get the output you required.

Chirag Ghori
  • 4,231
  • 2
  • 20
  • 35
Deepu
  • 83
  • 9
1

haha. That was easy.

SimpleDateFormat("dd MMM");

It's summer now and sunny,so I can't concetrate:):)

Theo
  • 3,099
  • 12
  • 53
  • 94