Java Code Examples for android.text.format.DateUtils#FORMAT_SHOW_DATE

The following examples show how to use android.text.format.DateUtils#FORMAT_SHOW_DATE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DatePickerDialog.java    From narrate-android with Apache License 2.0 6 votes vote down vote up
private void updateDisplay(boolean announce) {
    if (mDayOfWeekView != null) {
        mDayOfWeekView.setText(mCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG,
                Locale.getDefault()).toUpperCase(Locale.getDefault()));
    }

    mSelectedMonthTextView.setText(mCalendar.getDisplayName(Calendar.MONTH, Calendar.SHORT,
            Locale.getDefault()).toUpperCase(Locale.getDefault()));
    mSelectedDayTextView.setText(DAY_FORMAT.format(mCalendar.getTime()));
    mYearView.setText(YEAR_FORMAT.format(mCalendar.getTime()));

    // Accessibility.
    long millis = mCalendar.getTimeInMillis();
    mAnimator.setDateMillis(millis);
    int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR;
    String monthAndDayText = DateUtils.formatDateTime(getActivity(), millis, flags);
    mMonthAndDayView.setContentDescription(monthAndDayText);

    if (announce) {
        flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
        String fullDateText = DateUtils.formatDateTime(getActivity(), millis, flags);
        Utils.tryAccessibilityAnnounce(mAnimator, fullDateText);
    }
}
 
Example 2
Source File: DateFormatter.java    From opentasks with Apache License 2.0 6 votes vote down vote up
public int getDateUtilsFlags(Time now, Time date)
{
    if (now.year == date.year && now.yearDay == date.yearDay)
    {
        // today, show time only
        return FORMAT_SHOW_TIME;
    }
    else if (now.year == date.year)
    {
        // this year, don't include the year
        return DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_WEEKDAY;
    }
    else
    {
        return DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_WEEKDAY
                | DateUtils.FORMAT_ABBREV_WEEKDAY;
    }
}
 
Example 3
Source File: AccessibleDateAnimator.java    From cathode with Apache License 2.0 5 votes vote down vote up
/**
 * Announce the currently-selected date when launched.
 */
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        // Clear the event's current text so that only the current date will be spoken.
        event.getText().clear();
        int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR |
                DateUtils.FORMAT_SHOW_WEEKDAY;

        String dateString = DateUtils.formatDateTime(getContext(), mDateMillis, flags);
        event.getText().add(dateString);
        return true;
    }
    return super.dispatchPopulateAccessibilityEvent(event);
}
 
Example 4
Source File: AirMonthView.java    From AirCalendar with MIT License 5 votes vote down vote up
private String getMonthAndYearString() {
    int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NO_MONTH_DAY;
    mStringBuilder.setLength(0);

    long millis = mCalendar.getTimeInMillis();
    return DateUtils.formatDateRange(getContext(), millis, millis, flags);    // 지역화된 포멧으로 출력
}
 
Example 5
Source File: DatePickerDialog.java    From MaterialDateRangePicker with Apache License 2.0 5 votes vote down vote up
private void updateDisplay(boolean announce) {
    if (mDayOfWeekView != null) {
        mDayOfWeekView.setText(mCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG,
                Locale.getDefault()).toUpperCase(Locale.getDefault()));
    }

    mSelectedMonthTextView.setText(mCalendar.getDisplayName(Calendar.MONTH, Calendar.SHORT,
            Locale.getDefault()).toUpperCase(Locale.getDefault()));
    mSelectedMonthTextViewEnd.setText(mCalendarEnd.getDisplayName(Calendar.MONTH, Calendar.SHORT,
            Locale.getDefault()).toUpperCase(Locale.getDefault()));
    mSelectedDayTextView.setText(DAY_FORMAT.format(mCalendar.getTime()));
    mSelectedDayTextViewEnd.setText(DAY_FORMAT.format(mCalendarEnd.getTime()));
    mYearView.setText(YEAR_FORMAT.format(mCalendar.getTime()));
    mYearViewEnd.setText(YEAR_FORMAT.format(mCalendarEnd.getTime()));

    // Accessibility.
    long millis = mCalendar.getTimeInMillis();
    long millisEnd = mCalendarEnd.getTimeInMillis();
    mAnimator.setDateMillis(millis);
    mAnimatorEnd.setDateMillis(millisEnd);
    int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR;
    String monthAndDayText = DateUtils.formatDateTime(getActivity(), millis, flags);
    String monthAndDayTextEnd = DateUtils.formatDateTime(getActivity(), millisEnd, flags);
    mMonthAndDayView.setContentDescription(monthAndDayText);
    mMonthAndDayViewEnd.setContentDescription(monthAndDayTextEnd);

    if (announce) {
        flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
        String fullDateText = DateUtils.formatDateTime(getActivity(), millis, flags);
        String fullDateTextEnd = DateUtils.formatDateTime(getActivity(), millisEnd, flags);
        Utils.tryAccessibilityAnnounce(mAnimator, fullDateText);
        Utils.tryAccessibilityAnnounce(mAnimatorEnd, fullDateTextEnd);
    }
}
 
Example 6
Source File: Utils.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static String formatDateRange(Context context, long start, long end) {
	final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH;

	synchronized (sBuilder) {
		sBuilder.setLength(0);
		return DateUtils.formatDateRange(context, sFormatter, start, end,
				flags, null).toString();
	}
}
 
Example 7
Source File: AccessibleDateAnimator.java    From date_picker_converter with Apache License 2.0 5 votes vote down vote up
/**
 * Announce the currently-selected date when launched.
 */
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        // Clear the event's current text so that only the current date will be spoken.
        event.getText().clear();
        int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR |
                DateUtils.FORMAT_SHOW_WEEKDAY;

        String dateString = DateUtils.formatDateTime(getContext(), mDateMillis, flags);
        event.getText().add(dateString);
        return true;
    }
    return super.dispatchPopulateAccessibilityEvent(event);
}
 
Example 8
Source File: AccessibleDateAnimator.java    From MaterialDateRangePicker with Apache License 2.0 5 votes vote down vote up
/**
 * Announce the currently-selected date when launched.
 */
@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        // Clear the event's current text so that only the current date will be spoken.
        event.getText().clear();
        int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR |
                DateUtils.FORMAT_SHOW_WEEKDAY;

        String dateString = DateUtils.formatDateTime(getContext(), mDateMillis, flags);
        event.getText().add(dateString);
        return true;
    }
    return super.dispatchPopulateAccessibilityEvent(event);
}
 
Example 9
Source File: DatePickerSpinnerDelegate.java    From DateTimePicker with Apache License 2.0 5 votes vote down vote up
@Override
public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
    final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
    String selectedDateUtterance = DateUtils.formatDateTime(mContext,
            mCurrentDate.getTimeInMillis(), flags);
    event.getText().add(selectedDateUtterance);
}
 
Example 10
Source File: DateFormatter.java    From opentasks with Apache License 2.0 5 votes vote down vote up
@Override
public int getDateUtilsFlags(Time now, Time date)
{
    int result = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH;
    if (!date.allDay)
    {
        result |= FORMAT_SHOW_TIME;
    }
    if (now.year != date.year)
    {
        result |= DateUtils.FORMAT_SHOW_YEAR;
    }
    return result;
}
 
Example 11
Source File: SunshineDateUtils.java    From android-dev-challenge with Apache License 2.0 4 votes vote down vote up
/**
 * Helper method to convert the database representation of the date into something to display
 * to users.  As classy and polished a user experience as "20140102" is, we can do better.
 * <p/>
 * The day string for forecast uses the following logic:
 * For today: "Today, June 8"
 * For tomorrow:  "Tomorrow"
 * For the next 5 days: "Wednesday" (just the day name)
 * For all days after that: "Mon, Jun 8" (Mon, 8 Jun in UK, for example)
 *
 * @param context      Context to use for resource localization
 * @param dateInMillis The date in milliseconds (UTC)
 * @param showFullDate Used to show a fuller-version of the date, which always contains either
 *                     the day of the week, today, or tomorrow, in addition to the date.
 *
 * @return A user-friendly representation of the date such as "Today, June 8", "Tomorrow",
 * or "Friday"
 */
public static String getFriendlyDateString(Context context, long dateInMillis, boolean showFullDate) {

    long localDate = getLocalDateFromUTC(dateInMillis);
    long dayNumber = getDayNumber(localDate);
    long currentDayNumber = getDayNumber(System.currentTimeMillis());

    if (dayNumber == currentDayNumber || showFullDate) {
        /*
         * If the date we're building the String for is today's date, the format
         * is "Today, June 24"
         */
        String dayName = getDayName(context, localDate);
        String readableDate = getReadableDateString(context, localDate);
        if (dayNumber - currentDayNumber < 2) {
            /*
             * Since there is no localized format that returns "Today" or "Tomorrow" in the API
             * levels we have to support, we take the name of the day (from SimpleDateFormat)
             * and use it to replace the date from DateUtils. This isn't guaranteed to work,
             * but our testing so far has been conclusively positive.
             *
             * For information on a simpler API to use (on API > 18), please check out the
             * documentation on DateFormat#getBestDateTimePattern(Locale, String)
             * https://developer.android.com/reference/android/text/format/DateFormat.html#getBestDateTimePattern
             */
            String localizedDayName = new SimpleDateFormat("EEEE").format(localDate);
            return readableDate.replace(localizedDayName, dayName);
        } else {
            return readableDate;
        }
    } else if (dayNumber < currentDayNumber + 7) {
        /* If the input date is less than a week in the future, just return the day name. */
        return getDayName(context, localDate);
    } else {
        int flags = DateUtils.FORMAT_SHOW_DATE
                | DateUtils.FORMAT_NO_YEAR
                | DateUtils.FORMAT_ABBREV_ALL
                | DateUtils.FORMAT_SHOW_WEEKDAY;

        return DateUtils.formatDateTime(context, localDate, flags);
    }
}
 
Example 12
Source File: SunshineDateUtils.java    From android-dev-challenge with Apache License 2.0 4 votes vote down vote up
/**
 * Helper method to convert the database representation of the date into something to display
 * to users.  As classy and polished a user experience as "20140102" is, we can do better.
 * <p/>
 * The day string for forecast uses the following logic:
 * For today: "Today, June 8"
 * For tomorrow:  "Tomorrow"
 * For the next 5 days: "Wednesday" (just the day name)
 * For all days after that: "Mon, Jun 8" (Mon, 8 Jun in UK, for example)
 *
 * @param context      Context to use for resource localization
 * @param dateInMillis The date in milliseconds (UTC)
 * @param showFullDate Used to show a fuller-version of the date, which always contains either
 *                     the day of the week, today, or tomorrow, in addition to the date.
 *
 * @return A user-friendly representation of the date such as "Today, June 8", "Tomorrow",
 * or "Friday"
 */
public static String getFriendlyDateString(Context context, long dateInMillis, boolean showFullDate) {

    long localDate = getLocalDateFromUTC(dateInMillis);
    long dayNumber = getDayNumber(localDate);
    long currentDayNumber = getDayNumber(System.currentTimeMillis());

    if (dayNumber == currentDayNumber || showFullDate) {
        /*
         * If the date we're building the String for is today's date, the format
         * is "Today, June 24"
         */
        String dayName = getDayName(context, localDate);
        String readableDate = getReadableDateString(context, localDate);
        if (dayNumber - currentDayNumber < 2) {
            /*
             * Since there is no localized format that returns "Today" or "Tomorrow" in the API
             * levels we have to support, we take the name of the day (from SimpleDateFormat)
             * and use it to replace the date from DateUtils. This isn't guaranteed to work,
             * but our testing so far has been conclusively positive.
             *
             * For information on a simpler API to use (on API > 18), please check out the
             * documentation on DateFormat#getBestDateTimePattern(Locale, String)
             * https://developer.android.com/reference/android/text/format/DateFormat.html#getBestDateTimePattern
             */
            String localizedDayName = new SimpleDateFormat("EEEE").format(localDate);
            return readableDate.replace(localizedDayName, dayName);
        } else {
            return readableDate;
        }
    } else if (dayNumber < currentDayNumber + 7) {
        /* If the input date is less than a week in the future, just return the day name. */
        return getDayName(context, localDate);
    } else {
        int flags = DateUtils.FORMAT_SHOW_DATE
                | DateUtils.FORMAT_NO_YEAR
                | DateUtils.FORMAT_ABBREV_ALL
                | DateUtils.FORMAT_SHOW_WEEKDAY;

        return DateUtils.formatDateTime(context, localDate, flags);
    }
}
 
Example 13
Source File: SunshineDateUtils.java    From android-dev-challenge with Apache License 2.0 4 votes vote down vote up
/**
 * Helper method to convert the database representation of the date into something to display
 * to users. As classy and polished a user experience as "1474061664" is, we can do better.
 * <p/>
 * The day string for forecast uses the following logic:
 * For today: "Today, June 8"
 * For tomorrow:  "Tomorrow
 * For the next 5 days: "Wednesday" (just the day name)
 * For all days after that: "Mon, Jun 8" (Mon, 8 Jun in UK, for example)
 *
 * @param context               Context to use for resource localization
 * @param normalizedUtcMidnight The date in milliseconds (UTC midnight)
 * @param showFullDate          Used to show a fuller-version of the date, which always
 *                              contains either the day of the week, today, or tomorrow, in
 *                              addition to the date.
 *
 * @return A user-friendly representation of the date such as "Today, June 8", "Tomorrow",
 * or "Friday"
 */
public static String getFriendlyDateString(Context context, long normalizedUtcMidnight, boolean showFullDate) {

    /*
     * NOTE: localDate should be localDateMidnightMillis and should be straight from the
     * database
     *
     * Since we normalized the date when we inserted it into the database, we need to take
     * that normalized date and produce a date (in UTC time) that represents the local time
     * zone at midnight.
     */
    long localDate = getLocalMidnightFromNormalizedUtcDate(normalizedUtcMidnight);

    /*
     * In order to determine which day of the week we are creating a date string for, we need
     * to compare the number of days that have passed since the epoch (January 1, 1970 at
     * 00:00 GMT)
     */
    long daysFromEpochToProvidedDate = elapsedDaysSinceEpoch(localDate);

    /*
     * As a basis for comparison, we use the number of days that have passed from the epoch
     * until today.
     */
    long daysFromEpochToToday = elapsedDaysSinceEpoch(System.currentTimeMillis());

    if (daysFromEpochToProvidedDate == daysFromEpochToToday || showFullDate) {
        /*
         * If the date we're building the String for is today's date, the format
         * is "Today, June 24"
         */
        String dayName = getDayName(context, localDate);
        String readableDate = getReadableDateString(context, localDate);
        if (daysFromEpochToProvidedDate - daysFromEpochToToday < 2) {
            /*
             * Since there is no localized format that returns "Today" or "Tomorrow" in the API
             * levels we have to support, we take the name of the day (from SimpleDateFormat)
             * and use it to replace the date from DateUtils. This isn't guaranteed to work,
             * but our testing so far has been conclusively positive.
             *
             * For information on a simpler API to use (on API > 18), please check out the
             * documentation on DateFormat#getBestDateTimePattern(Locale, String)
             * https://developer.android.com/reference/android/text/format/DateFormat.html#getBestDateTimePattern
             */
            String localizedDayName = new SimpleDateFormat("EEEE").format(localDate);
            return readableDate.replace(localizedDayName, dayName);
        } else {
            return readableDate;
        }
    } else if (daysFromEpochToProvidedDate < daysFromEpochToToday + 7) {
        /* If the input date is less than a week in the future, just return the day name. */
        return getDayName(context, localDate);
    } else {
        int flags = DateUtils.FORMAT_SHOW_DATE
                | DateUtils.FORMAT_NO_YEAR
                | DateUtils.FORMAT_ABBREV_ALL
                | DateUtils.FORMAT_SHOW_WEEKDAY;

        return DateUtils.formatDateTime(context, localDate, flags);
    }
}
 
Example 14
Source File: DatePickerDialog.java    From date_picker_converter with Apache License 2.0 4 votes vote down vote up
private void setCurrentView(final int viewIndex) {
    long millis = Calendar.getInstance().getTimeInMillis();

    switch (viewIndex) {
        case MONTH_AND_DAY_VIEW:
            ObjectAnimator pulseAnimator = Utils.getPulseAnimator(mMonthAndDayView, 0.9f,
                    1.05f);
            if (mDelayAnimation) {
                pulseAnimator.setStartDelay(ANIMATION_DELAY);
                mDelayAnimation = false;
            }
            mDayPickerView.onDateChanged();
            if (mCurrentView != viewIndex) {
                mMonthAndDayView.setSelected(true);
                mYearView.setSelected(false);
                mAnimator.setDisplayedChild(MONTH_AND_DAY_VIEW);
                mCurrentView = viewIndex;
            }
            pulseAnimator.start();

            int flags = DateUtils.FORMAT_SHOW_DATE;
            String dayString = DateUtils.formatDateTime(getActivity(), millis, flags);
            mAnimator.setContentDescription(mDayPickerDescription + ": " + dayString);
            Utils.tryAccessibilityAnnounce(mAnimator, mSelectDay);
            break;
        case YEAR_VIEW:
            pulseAnimator = Utils.getPulseAnimator(mYearView, 0.85f, 1.1f);
            if (mDelayAnimation) {
                pulseAnimator.setStartDelay(ANIMATION_DELAY);
                mDelayAnimation = false;
            }
            mYearPickerView.onDateChanged();
            if (mCurrentView != viewIndex) {
                mMonthAndDayView.setSelected(false);
                mYearView.setSelected(true);
                mAnimator.setDisplayedChild(YEAR_VIEW);
                mCurrentView = viewIndex;
            }
            pulseAnimator.start();

            CharSequence yearString = YEAR_FORMAT.format(millis);
            mAnimator.setContentDescription(mYearPickerDescription + ": " + yearString);
            Utils.tryAccessibilityAnnounce(mAnimator, mSelectYear);
            break;
    }
}
 
Example 15
Source File: SunshineDateUtils.java    From android-dev-challenge with Apache License 2.0 4 votes vote down vote up
/**
 * Helper method to convert the database representation of the date into something to display
 * to users.  As classy and polished a user experience as "20140102" is, we can do better.
 * <p/>
 * The day string for forecast uses the following logic:
 * For today: "Today, June 8"
 * For tomorrow:  "Tomorrow"
 * For the next 5 days: "Wednesday" (just the day name)
 * For all days after that: "Mon, Jun 8" (Mon, 8 Jun in UK, for example)
 *
 * @param context      Context to use for resource localization
 * @param dateInMillis The date in milliseconds (UTC)
 * @param showFullDate Used to show a fuller-version of the date, which always contains either
 *                     the day of the week, today, or tomorrow, in addition to the date.
 *
 * @return A user-friendly representation of the date such as "Today, June 8", "Tomorrow",
 * or "Friday"
 */
public static String getFriendlyDateString(Context context, long dateInMillis, boolean showFullDate) {

    long localDate = getLocalDateFromUTC(dateInMillis);
    long dayNumber = getDayNumber(localDate);
    long currentDayNumber = getDayNumber(System.currentTimeMillis());

    if (dayNumber == currentDayNumber || showFullDate) {
        /*
         * If the date we're building the String for is today's date, the format
         * is "Today, June 24"
         */
        String dayName = getDayName(context, localDate);
        String readableDate = getReadableDateString(context, localDate);
        if (dayNumber - currentDayNumber < 2) {
            /*
             * Since there is no localized format that returns "Today" or "Tomorrow" in the API
             * levels we have to support, we take the name of the day (from SimpleDateFormat)
             * and use it to replace the date from DateUtils. This isn't guaranteed to work,
             * but our testing so far has been conclusively positive.
             *
             * For information on a simpler API to use (on API > 18), please check out the
             * documentation on DateFormat#getBestDateTimePattern(Locale, String)
             * https://developer.android.com/reference/android/text/format/DateFormat.html#getBestDateTimePattern
             */
            String localizedDayName = new SimpleDateFormat("EEEE").format(localDate);
            return readableDate.replace(localizedDayName, dayName);
        } else {
            return readableDate;
        }
    } else if (dayNumber < currentDayNumber + 7) {
        /* If the input date is less than a week in the future, just return the day name. */
        return getDayName(context, localDate);
    } else {
        int flags = DateUtils.FORMAT_SHOW_DATE
                | DateUtils.FORMAT_NO_YEAR
                | DateUtils.FORMAT_ABBREV_ALL
                | DateUtils.FORMAT_SHOW_WEEKDAY;

        return DateUtils.formatDateTime(context, localDate, flags);
    }
}
 
Example 16
Source File: SunshineDateUtils.java    From android-dev-challenge with Apache License 2.0 4 votes vote down vote up
/**
 * Helper method to convert the database representation of the date into something to display
 * to users.  As classy and polished a user experience as "20140102" is, we can do better.
 * <p/>
 * The day string for forecast uses the following logic:
 * For today: "Today, June 8"
 * For tomorrow:  "Tomorrow"
 * For the next 5 days: "Wednesday" (just the day name)
 * For all days after that: "Mon, Jun 8" (Mon, 8 Jun in UK, for example)
 *
 * @param context      Context to use for resource localization
 * @param dateInMillis The date in milliseconds (UTC)
 * @param showFullDate Used to show a fuller-version of the date, which always contains either
 *                     the day of the week, today, or tomorrow, in addition to the date.
 *
 * @return A user-friendly representation of the date such as "Today, June 8", "Tomorrow",
 * or "Friday"
 */
public static String getFriendlyDateString(Context context, long dateInMillis, boolean showFullDate) {

    long localDate = getLocalDateFromUTC(dateInMillis);
    long dayNumber = getDayNumber(localDate);
    long currentDayNumber = getDayNumber(System.currentTimeMillis());

    if (dayNumber == currentDayNumber || showFullDate) {
        /*
         * If the date we're building the String for is today's date, the format
         * is "Today, June 24"
         */
        String dayName = getDayName(context, localDate);
        String readableDate = getReadableDateString(context, localDate);
        if (dayNumber - currentDayNumber < 2) {
            /*
             * Since there is no localized format that returns "Today" or "Tomorrow" in the API
             * levels we have to support, we take the name of the day (from SimpleDateFormat)
             * and use it to replace the date from DateUtils. This isn't guaranteed to work,
             * but our testing so far has been conclusively positive.
             *
             * For information on a simpler API to use (on API > 18), please check out the
             * documentation on DateFormat#getBestDateTimePattern(Locale, String)
             * https://developer.android.com/reference/android/text/format/DateFormat.html#getBestDateTimePattern
             */
            String localizedDayName = new SimpleDateFormat("EEEE").format(localDate);
            return readableDate.replace(localizedDayName, dayName);
        } else {
            return readableDate;
        }
    } else if (dayNumber < currentDayNumber + 7) {
        /* If the input date is less than a week in the future, just return the day name. */
        return getDayName(context, localDate);
    } else {
        int flags = DateUtils.FORMAT_SHOW_DATE
                | DateUtils.FORMAT_NO_YEAR
                | DateUtils.FORMAT_ABBREV_ALL
                | DateUtils.FORMAT_SHOW_WEEKDAY;

        return DateUtils.formatDateTime(context, localDate, flags);
    }
}
 
Example 17
Source File: FormatterUtil.java    From social-app-android with Apache License 2.0 4 votes vote down vote up
private static String shortFormatEventDay(Context context, long time) {
    int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH;
    Formatter f = new Formatter(new StringBuilder(50), Locale.getDefault());
    return DateUtils.formatDateRange(context, f, time, time, flags).toString();
}
 
Example 18
Source File: DatePickerDialog.java    From BottomSheetPickers with Apache License 2.0 4 votes vote down vote up
private static String formatMonthAndDay(Calendar calendar) {
    int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_NO_YEAR;
    return formatDate(calendar, flags);
}
 
Example 19
Source File: SunshineDateUtils.java    From android-dev-challenge with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a date string in the format specified, which shows a date, without a year,
 * abbreviated, showing the full weekday.
 *
 * @param context      Used by DateUtils to formate the date in the current locale
 * @param timeInMillis Time in milliseconds since the epoch (local time)
 *
 * @return The formatted date string
 */
private static String getReadableDateString(Context context, long timeInMillis) {
    int flags = DateUtils.FORMAT_SHOW_DATE
            | DateUtils.FORMAT_NO_YEAR
            | DateUtils.FORMAT_SHOW_WEEKDAY;

    return DateUtils.formatDateTime(context, timeInMillis, flags);
}
 
Example 20
Source File: SunshineDateUtils.java    From android-dev-challenge with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a date string in the format specified, which shows an abbreviated date without a
 * year.
 *
 * @param context      Used by DateUtils to format the date in the current locale
 * @param timeInMillis Time in milliseconds since the epoch (local time)
 *
 * @return The formatted date string
 */
private static String getReadableDateString(Context context, long timeInMillis) {
    int flags = DateUtils.FORMAT_SHOW_DATE
            | DateUtils.FORMAT_NO_YEAR
            | DateUtils.FORMAT_SHOW_WEEKDAY;

    return DateUtils.formatDateTime(context, timeInMillis, flags);
}