Tuesday, 25 October 2011

Format date in java with months' name changed

I was given the task to format dates. The requester needed months' name appropriate case endings.

It can be done be SimpleDateFormat class: (this example is for Polish language)

SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMM-yyyy");
DateFormatSymbols dfs = new DateFormatSymbols();
dfs.setMonths(new String[]{"stycznia","lutego","marca","kwietnia","maja","czerwca","lipca","sierpnia","września","października","listopada","grudnia"});
sdf.setDateFormatSymbols(dfs);
String output = sdf.format(new Date());

No comments: