Example usage for android.text.format DateUtils formatDateRange

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

Introduction

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

Prototype

public static Formatter formatDateRange(Context context, Formatter formatter, long startMillis, long endMillis,
        int flags) 

Source Link

Document

Formats a date or a time range according to the local conventions.

Usage

From source file:com.dgsd.android.ShiftTracker.Adapter.DayAdapter.java

private String getTimeText(Shift shift) {
    String time = mIdToTimeArray.get((int) shift.id);
    if (!TextUtils.isEmpty(time))
        return time;

    int flags = DateUtils.FORMAT_SHOW_TIME;
    if (mIs24Hour)
        flags |= DateUtils.FORMAT_24HOUR;

    mStringBuilder.setLength(0);//from  w  ww.  j  av  a2  s  .  c o  m
    time = DateUtils.formatDateRange(mContext, mFormatter, shift.getStartTime(), shift.getEndTime(), flags)
            .toString();

    time += " (" + UIUtils.getDurationAsHours(shift.getDurationInMinutes()) + ")";

    mIdToTimeArray.put((int) shift.id, time);
    return time;
}

From source file:com.dgsd.android.ShiftTracker.Adapter.WeekAdapter.java

private String getTimeText(Shift shift) {
    String time = mIdToTimeArray.get((int) shift.id);
    if (!TextUtils.isEmpty(time))
        return time;

    int flags = DateUtils.FORMAT_SHOW_TIME;
    if (mIs24Hour)
        flags |= DateUtils.FORMAT_24HOUR;

    mStringBuilder.setLength(0);//www  .  j  ava 2  s.  co  m
    time = DateUtils.formatDateRange(getContext(), mFormatter, shift.getStartTime(), shift.getEndTime(), flags)
            .toString();

    time += " (" + UIUtils.getDurationAsHours(shift.getDurationInMinutes()) + ")";

    mIdToTimeArray.put((int) shift.id, time);
    return time;
}

From source file:im.neon.adapters.VectorMessagesAdapter.java

/**
 * Converts a difference of days to a string.
 * @param date the date to display/*from   w w  w.  jav  a  2 s  .  c  om*/
 * @param nbrDays the number of days between the reference days
 * @return the date text
 */
private String dateDiff(Date date, long nbrDays) {
    if (nbrDays == 0) {
        return mContext.getResources().getString(R.string.today);
    } else if (nbrDays == 1) {
        return mContext.getResources().getString(R.string.yesterday);
    } else if (nbrDays < 7) {
        return (new SimpleDateFormat("EEEE", AdapterUtils.getLocale(mContext))).format(date);
    } else {
        int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_ABBREV_ALL
                | DateUtils.FORMAT_SHOW_WEEKDAY;

        Formatter f = new Formatter(new StringBuilder(50), AdapterUtils.getLocale(mContext));
        return DateUtils.formatDateRange(mContext, f, date.getTime(), date.getTime(), flags).toString();
    }
}

From source file:cn.suishen.email.activity.MessageViewFragmentBase.java

/**
 * @return the given date/time in a human readable form.  The returned string always have
 *     month and day (and year if {@code withYear} is set), so is usually long.
 *     Use {@link DateUtils#getRelativeTimeSpanString} instead to save the screen real estate.
 *///w  w w  .j  a va 2  s.co m
private String formatDate(long millis, boolean withYear) {
    StringBuilder sb = new StringBuilder();
    Formatter formatter = new Formatter(sb);
    DateUtils.formatDateRange(mContext, formatter, millis, millis,
            DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_TIME
                    | (withYear ? DateUtils.FORMAT_SHOW_YEAR : DateUtils.FORMAT_NO_YEAR));
    return sb.toString();
}