Can I format a JodaTime date
Yes. You want a DateTimeFormatter
.
DateTimeFormatter formatter = DateTimeFormat.forPattern("dd-MMM-yy") .withLocale(Locale.US); // Make sure we use English month names String text = formatter.format(date1);
This will give 02-Jul-13, but you can always uppercase.
For more information, see Login and Logout in the User Guide.
EDIT: Alternatively, as Rohit suggests:
String text = date1.toString("dd-MMM-yy", Locale.US);
Personally, I would prefer to create the formatter once as a constant, and reuse it wherever you need it, but it is up to you.
Jon Skeet Jul 03 '13 at 14:37 2013-07-03 14:37
source share