「1ST OCT」のような日付と月を表示したいのですが、「2016年10月17日月曜日」の日付が表示され、以下のコードを使用しています。JSFの日付形式を1STのように変更します。
<ice:outputLabel value="#{currentRow.eventDate}">
<f:convertDateTime dateStyle="full" timeZone="#{AnnouncementBean.timeZone}" />
</ice:outputLabel>
「1ST OCT」のような日付と月を表示したいのですが、「2016年10月17日月曜日」の日付が表示され、以下のコードを使用しています。JSFの日付形式を1STのように変更します。
<ice:outputLabel value="#{currentRow.eventDate}">
<f:convertDateTime dateStyle="full" timeZone="#{AnnouncementBean.timeZone}" />
</ice:outputLabel>
f:convertDateTime
の代わりにjavaコードで手動で日付をフォーマットすることができます。
新しい文字列変数を宣言するだけで、次のメソッドを使用して日付buを書式設定する必要があります。
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ですが、私の要件はf:convertDateTimeを使って日付をフォーマットすることです。 –
@Muhammad: 'f:convertDateTime' APIをチェックし、サポートされているかどうかを確認してください。そうでない場合は、独自のコードを作成するか、Javaコード – Kukeltje
で使用してください。 "st"、 "nd"、 "rd"または "th"を返す方法がある方がよいでしょう。今、(ほぼ)重複がたくさんあります。 –
Javaの「11th」、「21st」、または「23rd」と言うと、どのように月の書式を設定しますか? (序数)](http://stackoverflow.com/questions/4011075/how-do-you-format-the-day-of-the-month-to-say-11th-21st-or-23rd-in- java) –
Stack Overflowで何回も返答しました。キーワードは "ordinal"です。 –
可能な複製とカスタムコンバータの作成方法の検索を組み合わせてください。 –