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

The following examples show how to use android.text.format.DateUtils#FORMAT_NO_MONTH_DAY . 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: CalendarViewLegacyDelegate.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the month displayed at the top of this view based on time. Override
 * to add custom events when the title is changed.
 *
 * @param calendar A day in the new focus month.
 */
private void setMonthDisplayed(Calendar calendar) {
    mCurrentMonthDisplayed = calendar.get(Calendar.MONTH);
    mAdapter.setFocusMonth(mCurrentMonthDisplayed);
    final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_MONTH_DAY
            | DateUtils.FORMAT_SHOW_YEAR;
    final long millis = calendar.getTimeInMillis();
    String newMonthName = DateUtils.formatDateRange(mContext, millis, millis, flags);
    mMonthName.setText(newMonthName);
    mMonthName.invalidate();
}
 
Example 2
Source File: TimeUtils.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
public static String getNoMonthDay(Context context, Date date) {
    if (date == null) return "";
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    int flags = DateUtils.FORMAT_ABBREV_MONTH;
    flags |= DateUtils.FORMAT_NO_MONTH_DAY;
    flags = flags | DateUtils.FORMAT_SHOW_YEAR;
    return DateUtils.formatDateTime(context, date.getTime(), flags);
}
 
Example 3
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 4
Source File: MonthView.java    From narrate-android with Apache License 2.0 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(), mFormatter, millis, millis, flags,
            Time.getCurrentTimezone()).toString();
}
 
Example 5
Source File: MonthView.java    From BottomSheetPickers with Apache License 2.0 5 votes vote down vote up
String getMonthAndYearString() {
    if (mMonthTitle == null) {
        int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR
                | DateUtils.FORMAT_NO_MONTH_DAY;
        mMonthTitle = DateFormatHelper.formatDate(mCalendar, flags);
    }
    return mMonthTitle;
}
 
Example 6
Source File: SimpleMonthView.java    From CalendarView with Apache License 2.0 5 votes vote down vote up
/**
 * 获取年份和月份
 *
 * @return
 */
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 7
Source File: MonthView.java    From MaterialDateRangePicker with Apache License 2.0 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(), mFormatter, millis, millis, flags, null).toString();
}
 
Example 8
Source File: MonthView.java    From StyleableDateTimePicker 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(), mFormatter, millis, millis, flags,
            Time.getCurrentTimezone()).toString();
}
 
Example 9
Source File: MonthView.java    From cathode with Apache License 2.0 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(), mFormatter, millis, millis, flags,
      Time.getCurrentTimezone()).toString();
}
 
Example 10
Source File: MainActivity.java    From samples with MIT License 4 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    final long min;
    switch (item.getItemId()) {
        case R.id.min_0:
            min = 0l;
            break;
        case R.id.min_min:
            min = DateUtils.MINUTE_IN_MILLIS;
            break;
        case R.id.min_hour:
            min = DateUtils.HOUR_IN_MILLIS;
            break;
        case R.id.min_day:
            min = DateUtils.DAY_IN_MILLIS;
            break;
        default:
            min = -1;
            break;
    }

    if (min >= 0) {
        item.setChecked(true);
        mAdapter.setMinResolution(min);
        return true;
    }

    item.setChecked(!item.isChecked());
    final int flag;
    switch (item.getItemId()) {
        case R.id.FORMAT_SHOW_TIME:
            flag = DateUtils.FORMAT_SHOW_TIME;
            break;
        case R.id.FORMAT_SHOW_WEEKDAY:
            flag = DateUtils.FORMAT_SHOW_WEEKDAY;
            break;
        case R.id.FORMAT_SHOW_YEAR:
            flag = DateUtils.FORMAT_SHOW_YEAR;
            break;
        case R.id.FORMAT_NO_YEAR:
            flag = DateUtils.FORMAT_NO_YEAR;
            break;
        case R.id.FORMAT_SHOW_DATE:
            flag = DateUtils.FORMAT_SHOW_DATE;
            break;
        case R.id.FORMAT_NO_MONTH_DAY:
            flag = DateUtils.FORMAT_NO_MONTH_DAY;
            break;
        case R.id.FORMAT_NO_NOON:
            flag = DateUtils.FORMAT_NO_NOON;
            break;
        case R.id.FORMAT_NO_MIDNIGHT:
            flag = DateUtils.FORMAT_NO_MIDNIGHT;
            break;
        case R.id.FORMAT_ABBREV_TIME:
            flag = DateUtils.FORMAT_ABBREV_TIME;
            break;
        case R.id.FORMAT_ABBREV_WEEKDAY:
            flag = DateUtils.FORMAT_ABBREV_WEEKDAY;
            break;
        case R.id.FORMAT_ABBREV_MONTH:
            flag = DateUtils.FORMAT_ABBREV_MONTH;
            break;
        case R.id.FORMAT_NUMERIC_DATE:
            flag = DateUtils.FORMAT_NUMERIC_DATE;
            break;
        case R.id.FORMAT_ABBREV_RELATIVE:
            flag = DateUtils.FORMAT_ABBREV_RELATIVE;
            break;
        case R.id.FORMAT_ABBREV_ALL:
            flag = DateUtils.FORMAT_ABBREV_ALL;
            break;
        default:
            throw new UnsupportedOperationException("unknown id");
    }

    if (item.isChecked()) {
        mAdapter.addFlag(flag);
    } else {
        mAdapter.removeFlag(flag);
    }

    return true;
}
 
Example 11
Source File: SimpleMonthView.java    From Conquer with Apache License 2.0 4 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 12
Source File: SimpleMonthView.java    From UltimateAndroid with Apache License 2.0 4 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 13
Source File: SimpleMonthView.java    From UltimateAndroid with Apache License 2.0 4 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 14
Source File: SimpleMonthView.java    From CalendarListview with MIT License 4 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 15
Source File: CalendarPickerView.java    From android-times-square with Apache License 2.0 4 votes vote down vote up
/**
 * Use {@link DateUtils} to format the dates.
 *
 * @see DateUtils
 */
private String formatMonthDate(Date date) {
  int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR
          | DateUtils.FORMAT_NO_MONTH_DAY;

  // Save default Locale
  Locale defaultLocale = Locale.getDefault();

  // Set new default Locale, the reason to do that is DateUtils.formatDateTime uses
  // internally this method DateIntervalFormat.formatDateRange to format the date. And this
  // method uses the default locale.
  //
  // More details about the methods:
  // - DateUtils.formatDateTime: https://goo.gl/3YW52Q
  // - DateIntervalFormat.formatDateRange: https://goo.gl/RRmfK7
  Locale.setDefault(locale);

  String dateFormatted;
  if (displayAlwaysDigitNumbers
    && explicitlyNumericYearLocaleLanguages.contains(locale.getLanguage())) {
    StringBuilder sb = new StringBuilder();
    SimpleDateFormat sdfMonth = new SimpleDateFormat(getContext()
      .getString(R.string.month_only_name_format), locale);
    SimpleDateFormat sdfYear = new SimpleDateFormat(getContext()
      .getString(R.string.year_only_format), Locale.ENGLISH);
    dateFormatted = sb.append(sdfMonth.format(date.getTime())).append(" ")
      .append(sdfYear.format(date.getTime())).toString();
  } else {
    // Format date using the new Locale
    dateFormatted = DateUtils.formatDateRange(getContext(), monthFormatter,
      date.getTime(), date.getTime(), flags, timeZone.getID()).toString();
  }
  // Call setLength(0) on StringBuilder passed to the Formatter constructor to not accumulate
  // the results
  monthBuilder.setLength(0);

  // Restore default Locale to avoid generating any side effects
  Locale.setDefault(defaultLocale);

  return dateFormatted;
}