I am using the SimpleDateFormatter
public static final DateFormat DATE_FORMAT_FULL_FULL_SPACES =
new SimpleDateFormat("dd MMMM yyyy", Locale.getDefault());
and Current Date
is passed at that time, It should display as
1st JULY 2014
where st should be superscript.
How can I go further ?
Create these methods
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>";
}
}
How to call?
String str = getFormatedDate();
txtDate.setText(Html.fromHtml(str));
OutPut :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With