-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
  • 166,747
  • 40
  • 210
  • 420
001
  • 59,081
  • 87
  • 224
  • 333

3 Answers3

1

And date represents instance of java.util.Date

String formattedDate = new SimpleDateFormat("dd MMM yyyy").format(date);
sanbhat
  • 17,162
  • 6
  • 47
  • 63
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
  • 35,944
  • 10
  • 64
  • 76
0

I would use the localized approach as described here:

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