当前位置: 首页>>代码示例>>Java>>正文


Java DateUtils.FORMAT_NO_YEAR属性代码示例

本文整理汇总了Java中android.text.format.DateUtils.FORMAT_NO_YEAR属性的典型用法代码示例。如果您正苦于以下问题:Java DateUtils.FORMAT_NO_YEAR属性的具体用法?Java DateUtils.FORMAT_NO_YEAR怎么用?Java DateUtils.FORMAT_NO_YEAR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.text.format.DateUtils的用法示例。


在下文中一共展示了DateUtils.FORMAT_NO_YEAR属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateDisplay

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()));*/

       if (this.mDayOfWeekView != null){
           this.mCalendar.setFirstDayOfWeek(mWeekStart);
           this.mDayOfWeekView.setText(mDateFormatSymbols.getWeekdays()[this.mCalendar.get(Calendar.DAY_OF_WEEK)].toUpperCase(Locale.getDefault()));
       }

       this.mSelectedMonthTextView.setText(mDateFormatSymbols.getMonths()[this.mCalendar.get(Calendar.MONTH)].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);
       }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:32,代码来源:DatePickerDialog.java

示例2: updateDisplay

private void updateDisplay(boolean announce) {
    mYearView.setText(YEAR_FORMAT.format(mCalendar.getTime()));

    if (mVersion == Version.VERSION_1) {
        if (mDatePickerHeaderView != null) {
            if (mTitle != null)
                mDatePickerHeaderView.setText(mTitle.toUpperCase(Locale.getDefault()));
            else {
                mDatePickerHeaderView.setText(mCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG,
                        Locale.getDefault()).toUpperCase(Locale.getDefault()));
            }
        }
        mSelectedMonthTextView.setText(MONTH_FORMAT.format(mCalendar.getTime()));
        mSelectedDayTextView.setText(DAY_FORMAT.format(mCalendar.getTime()));
    }

    if (mVersion == Version.VERSION_2) {
        mSelectedDayTextView.setText(VERSION_2_FORMAT.format(mCalendar.getTime()));
        if (mTitle != null)
            mDatePickerHeaderView.setText(mTitle.toUpperCase(Locale.getDefault()));
        else
            mDatePickerHeaderView.setVisibility(View.GONE);
    }

    // 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);
    }
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:37,代码来源:DatePickerDialog.java

示例3: getFriendlyDateString

/**
 * 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);
    }
}
 
开发者ID:rashikaranpuria,项目名称:ubiquitous,代码行数:79,代码来源:SunshineDateUtils.java

示例4: getFriendlyDateString

/**
 * 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);
    }
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:59,代码来源:SunshineDateUtils.java

示例5: getReadableDateString

/**
 * 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);
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:16,代码来源:SunshineDateUtils.java

示例6: getReadableDateString

/**
 * 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);
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:16,代码来源:SunshineDateUtils.java


注:本文中的android.text.format.DateUtils.FORMAT_NO_YEAR属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。