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 String formatDateRange(Context context, 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.Fragment.EditShiftFragment.java

@Override
public void onDateSelected(int typeCode, int julianDay) {
    if (getActivity() == null)
        return;/*from   w  w w  . ja v  a 2  s  .  c  om*/

    final long millis = TimeUtils.getStartMillisForJulianDay(julianDay);
    String formatted = DateUtils.formatDateRange(getActivity(), millis, millis,
            DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_DATE);

    if (typeCode == TYPE_CODE_START) {
        mStartDate.setTag(julianDay);
        mStartDate.setText(formatted);
    } else {
        mEndDate.setTag(julianDay);
        mEndDate.setText(formatted);
    }
}

From source file:com.dgsd.android.ShiftTracker.Fragment.EditShiftFragment.java

@Override
public void onTimeSelected(long millis) {
    if (getActivity() == null)
        return;// ww w.j  a  v  a2s .  c om

    TextView tv = null;
    if (mLastTimeSelected == LastTimeSelected.START)
        tv = mStartTime;
    else if (mLastTimeSelected == LastTimeSelected.END)
        tv = mEndTime;
    else
        return; //O no! This should never happen!

    tv.setTag(millis);

    int flags = DateUtils.FORMAT_SHOW_TIME;
    if (DateFormat.is24HourFormat(getActivity()))
        flags |= DateUtils.FORMAT_24HOUR;
    else
        flags |= DateUtils.FORMAT_12HOUR;

    tv.setError(null);
    tv.setText(DateUtils.formatDateRange(getActivity(), millis, millis, flags));
}