-1

I want to display date and month like "1ST OCT" while I am getting date "Monday, October 17, 2016" and I am using below code, any help would be appriciated.

<ice:outputLabel value="#{currentRow.eventDate}">
       <f:convertDateTime dateStyle="full" timeZone="#{AnnouncementBean.timeZone}" />
 </ice:outputLabel>
Tiny
  • 27,221
  • 105
  • 339
  • 599
Muhammad Essa
  • 142
  • 1
  • 10
  • 1
    Possible duplicate of [How do you format the day of the month to say "11th", "21st" or "23rd" in Java? (ordinal indicator)](http://stackoverflow.com/questions/4011075/how-do-you-format-the-day-of-the-month-to-say-11th-21st-or-23rd-in-java) – Basil Bourque Oct 20 '16 at 05:38
  • Answered many times on Stack Overflow. Key word is "ordinal". – Basil Bourque Oct 20 '16 at 05:39
  • Combine the possible duplicate with a search on how to create a custom converter. – Jasper de Vries Oct 20 '16 at 11:11

1 Answers1

1

You can format your date manually in java code instead of using f:convertDateTime.

You just need to declare new String variable and which is formatted date bu using following method.

public static String getFormattedDate(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        // 2nd of march 2015
        int day = cal.get(Calendar.DATE);

        if (!((day > 10) && (day < 19)))
            switch (day % 10) {
            case 1:
                return new SimpleDateFormat("d'st' 'of' MMM").format(date);
            case 2:
                return new SimpleDateFormat("d'nd' 'of' MMM").format(date);
            case 3:
                return new SimpleDateFormat("d'rd' 'of' MMM").format(date);
            default:
                return new SimpleDateFormat("d'th' 'of' MMM").format(date);
            }
        return new SimpleDateFormat("d'th' 'of' MMM").format(date);
    }
Sarz
  • 1,970
  • 4
  • 23
  • 43
  • Hi Sarz, but my requirement is to format date using f:convertDateTime – Muhammad Essa Oct 20 '16 at 09:14
  • 2
    @Muhammad: Then check the `f:convertDateTime` api and see if it is supported. If not, either create your own or use it in java code – Kukeltje Oct 20 '16 at 09:59
  • You will probably be better of having an extra method to return "st", "nd", "rd" or "th". Now there are a lot of (almost) duplicates. – Jasper de Vries Oct 20 '16 at 11:15
  • Yes @JasperdeVries you are right, We have alternate ways too. – Sarz Oct 20 '16 at 11:57
  • @Muhammad f:convertDateTime provides this format you can use it directly, If not you have to find some alternates to achieve it. – Sarz Oct 20 '16 at 12:00