I am using the SimpleDateFormatter
public static final DateFormat DATE_FORMAT_FULL_FULL_SPACES =
new SimpleDateFormat(\"dd MMMM yyyy\", Local
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 "th";
}
switch (day % 10) {
case 1:
return "st";
case 2:
return "nd";
case 3:
return "rd";
default:
return "th";
}
}
How to call?
String str = getFormatedDate();
txtDate.setText(Html.fromHtml(str));
OutPut :