Is it possible to format JodaTime Date.
Here is the code:
private static LocalDate priorDay(LocalDate date1) {
do {
date1 = date1.plusDays(-1);
} while (date1.getDayOfWeek() == DateTimeConstants.SUNDAY ||
date1.getDayOfWeek() == DateTimeConstants.SATURDAY);
//System.out.print(date1);
return date1;
}
Here date1 returns as: 2013-07-02 but i would like as 02-JUL-13
Thanks in advance
Check out the Joda DateTimeFormatter.
You probably want to use it via something like:
This is a much better solution than the existing SimpleDateFormat class. The Joda variant is thread-safe. The old Java variant is (counterintuitively) not thread-safe!
Yes. You want
DateTimeFormatter
.That will give 02-Jul-13, but you can always upper-case it.
See the Input and Output part of the user guide for more information.
EDIT: Alternatively, as suggested by Rohit:
Personally I'd prefer to create the formatter once, as a constant, and reuse it everywhere you need it, but it's up to you.