Example usage for java.util Calendar SHORT

List of usage examples for java.util Calendar SHORT

Introduction

In this page you can find the example usage for java.util Calendar SHORT.

Prototype

int SHORT

To view the source code for java.util Calendar SHORT.

Click Source Link

Document

A style specifier for #getDisplayName(int,int,Locale) getDisplayName and #getDisplayNames(int,int,Locale) getDisplayNames equivalent to #SHORT_FORMAT .

Usage

From source file:com.leavjenn.smoothdaterangepicker.date.SmoothDateRangePickerFragment.java

private void updateDisplay(boolean announce) {
    if (mDayOfWeekView != null && mDayOfWeekViewEnd != null) {
        mDayOfWeekView/* www  .java2s .com*/
                .setText(mCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault())
                        .toUpperCase(Locale.getDefault()));
        mDayOfWeekViewEnd
                .setText(mCalendarEnd.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()));
    mDuration = Utils.daysBetween(mCalendar, mCalendarEnd);
    mDurationTextView.setText(String.valueOf(mDuration));
    mDurationDayTextView.setText(mDuration > 1 ? getString(R.string.days) : getString(R.string.day));

    // Accessibility.
    long millis = mCalendar.getTimeInMillis();
    long millisEnd = mCalendarEnd.getTimeInMillis();
    mAnimator.setDateMillis(millis);
    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);
    }
}

From source file:com.borax12.materialdaterangepicker.date.DatePickerDialog.java

private void updateDisplay(boolean announce) {
    if (mDayOfWeekView != null) {
        mDayOfWeekView/*w ww  . ja  va  2 s  .c o  m*/
                .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);
    }
}

From source file:com.kenmeidearu.materialdatetimepicker.date.DatePickerDialog.java

private void updateDisplay(boolean announce) {
    if (mDayOfWeekView != null) {
        if (mTitle != null)
            mDayOfWeekView.setText(mTitle.toUpperCase(Locale.getDefault()));
        else {/*from  www.  java  2  s .co  m*/
            if (mCalendar != null) {
                mDayOfWeekView.setText(
                        mCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault())
                                .toUpperCase(Locale.getDefault()));
            }
        }
    }

    if (mSelectedMonthTextView != null)
        mSelectedMonthTextView
                .setText(mCalendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault())
                        .toUpperCase(Locale.getDefault()));
    if (mSelectedDayTextView != null)
        mSelectedDayTextView.setText(DAY_FORMAT.format(mCalendar.getTime()));
    if (mYearView != null)
        mYearView.setText(YEAR_FORMAT.format(mCalendar.getTime()));
    setHour(mInitialTime.getHour());
    setMinute(mInitialTime.getMinute());
    setSecond(mInitialTime.getSecond());
    //mHourView.setText(HOUR_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);
    mDayOfWeekView.setContentDescription(monthAndDayText);//tadinya month and day view

    if (announce) {
        flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
        String fullDateText = DateUtils.formatDateTime(getActivity(), millis, flags);
        Utils.tryAccessibilityAnnounce(mAnimator, fullDateText);
    }
}

From source file:org.botlibre.util.Utils.java

public static String displayTimestamp(Date date) {
    if (date == null) {
        return "";
    }/* w  w w . ja  va2  s  .  c  o  m*/
    StringWriter writer = new StringWriter();
    Calendar today = Calendar.getInstance();
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR)
            && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) {
        writer.write("Today");
    } else if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR)
            && calendar.get(Calendar.DAY_OF_YEAR) == (today.get(Calendar.DAY_OF_YEAR) - 1)) {
        writer.write("Yesterday");
    } else {
        writer.write(calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US));
        writer.write(" ");
        writer.write(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
        if (calendar.get(Calendar.YEAR) != today.get(Calendar.YEAR)) {
            writer.write(" ");
            writer.write(String.valueOf(calendar.get(Calendar.YEAR)));
        }
    }
    writer.write(", ");
    writer.write(String.valueOf(calendar.get(Calendar.HOUR_OF_DAY)));
    writer.write(":");
    if (calendar.get(Calendar.MINUTE) < 10) {
        writer.write("0");
    }
    writer.write(String.valueOf(calendar.get(Calendar.MINUTE)));

    return writer.toString();
}

From source file:org.botlibre.util.Utils.java

public static String displayDate(Date date) {
    if (date == null) {
        return "";
    }/*from   ww  w  .  jav  a  2 s . c om*/
    StringWriter writer = new StringWriter();
    Calendar today = Calendar.getInstance();
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR)
            && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) {
        writer.write("Today");
    } else if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR)
            && calendar.get(Calendar.DAY_OF_YEAR) == (today.get(Calendar.DAY_OF_YEAR) - 1)) {
        writer.write("Yesterday");
    } else {
        writer.write(calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US));
        writer.write(" ");
        writer.write(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)));
        if (calendar.get(Calendar.YEAR) != today.get(Calendar.YEAR)) {
            writer.write(" ");
            writer.write(String.valueOf(calendar.get(Calendar.YEAR)));
        }
    }

    return writer.toString();
}