Example usage for android.text.format DateUtils FORMAT_NO_NOON_MIDNIGHT

List of usage examples for android.text.format DateUtils FORMAT_NO_NOON_MIDNIGHT

Introduction

In this page you can find the example usage for android.text.format DateUtils FORMAT_NO_NOON_MIDNIGHT.

Prototype

int FORMAT_NO_NOON_MIDNIGHT

To view the source code for android.text.format DateUtils FORMAT_NO_NOON_MIDNIGHT.

Click Source Link

Usage

From source file:com.android.mms.ui.MessageUtils.java

public static String getTimeDividerString(Context context, long when) {
    Time then = new Time();
    then.set(when);/* w ww. j a  v  a 2 s .  co m*/
    Time now = new Time();
    now.setToNow();

    // Basic settings for formatDateTime() we want for all cases.
    int formatFlags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL
            | DateUtils.FORMAT_CAP_AMPM;

    // If the message is from a different year, show the date and year.
    if (then.year != now.year) {
        formatFlags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
    } else if (then.yearDay != now.yearDay) {
        // If it is from a different day than today, show only the date.
        formatFlags |= DateUtils.FORMAT_SHOW_DATE;
        Date curDate = new Date();
        Date cur = new Date(curDate.getYear(), curDate.getMonth(), curDate.getDate(), 0, 0, 0);
        long oneDay = 24 * 60 * 60 * 1000;
        long elapsedTime = cur.getTime() - when;
        if (elapsedTime < oneDay && elapsedTime > 0) {
            return context.getResources().getString(R.string.str_ipmsg_yesterday);
        }
    } else {
        return context.getString(R.string.str_ipmsg_today);
    }
    return DateUtils.formatDateTime(context, when, formatFlags);
}

From source file:com.android.mms.ui.MessageUtils.java

public static String getShortTimeString(Context context, long time) {
    int formatFlags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_CAP_AMPM;
    formatFlags |= DateUtils.FORMAT_SHOW_TIME;
    return DateUtils.formatDateTime(context, time, formatFlags);

}