I have a date textview. And my textview holds a date string like 2011.09.17. Well I still do want to have that but I also want to add some more user friendly info for some speci
public class RelativeWeekday {
private final Calendar mCalendar;
public RelativeWeekday(Calendar calendar) {
mCalendar = calendar;
}
@Override
public String toString() {
Calendar today = Calendar.getInstance(Locale.getDefault());
int dayOfYear = mCalendar.get(Calendar.DAY_OF_YEAR);
if (Math.abs(dayOfYear - today.get(Calendar.DAY_OF_YEAR)) < 2) {
return getRelativeDay(today);
}
return getWeekDay();
}
private String getRelativeDay(Calendar today) {
return DateUtils.getRelativeTimeSpanString(
mCalendar.getTimeInMillis(),
today.getTimeInMillis(),
DateUtils.DAY_IN_MILLIS,
DateUtils.FORMAT_SHOW_WEEKDAY).toString();
}
private String getWeekDay() {
SimpleDateFormat dayFormat = new SimpleDateFormat("EEEE");
return dayFormat.format(mCalendar.getTimeInMillis());
}
}