如何将带后缀的当前日期格式化为上标? [英] How to format the current date with Suffix to Superscript?
本文介绍了如何将带后缀的当前日期格式化为上标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 SimpleDateFormatter
public static final DateFormat DATE_FORMAT_FULL_FULL_SPACES =
new SimpleDateFormat("dd MMMM yyyy", Locale.getDefault());
此时传递了
和当前日期
,应显示为 2014年7月1日
,其中st应该是上标.
and Current Date
is passed at that time, It should display as
1st JULY 2014
where st should be superscript.
我该怎么走?
推荐答案
创建这些方法
private String getFormatedDate(){
String dayNumberSuffix = getDayNumberSuffix(Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
SimpleDateFormat dateFormat = new SimpleDateFormat(" d'" + dayNumberSuffix + "' MMMM yyyy");
return dateFormat.format(Calendar.getInstance().getTime());
}
private String getDayNumberSuffix(int day) {
if (day >= 11 && day <= 13) {
return "<sup>th</sup>";
}
switch (day % 10) {
case 1:
return "<sup>st</sup>";
case 2:
return "<sup>nd</sup>";
case 3:
return "<sup>rd</sup>";
default:
return "<sup>th</sup>";
}
}
如何拨打电话?
String str = getFormatedDate();
txtDate.setText(Html.fromHtml(str));
输出:
这篇关于如何将带后缀的当前日期格式化为上标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文