-6

Given DateTime, how to format date in the following format ?

12 JUL 2013

in c#, you do this

string formatedDateString = String.Format("{0:dd MMM yyyy}", myDateTime);

What is the equivalent code in JAVA ?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
001
  • 62,807
  • 94
  • 230
  • 350

3 Answers3

1

And date represents instance of java.util.Date

String formattedDate = new SimpleDateFormat("dd MMM yyyy").format(date);
sanbhat
  • 17,522
  • 6
  • 48
  • 64
0

Use a SimpleDateFormat. Along the lines of

(new SimpleDateFormat("dd MMM yyyy")).parse("12 JUL 2013");
(new SimpleDateFormat("dd MMM yyyy")).format(new Date());
Andreas Wederbrand
  • 38,065
  • 11
  • 68
  • 78
0

I would use the localized approach as described here:

String formattedDate = DateFormat.getDateInstance().format(date);
winne2
  • 2,188
  • 2
  • 17
  • 13