當前位置: 首頁>>代碼示例>>Java>>正文


Java DateFormat.getBestDateTimePattern方法代碼示例

本文整理匯總了Java中android.text.format.DateFormat.getBestDateTimePattern方法的典型用法代碼示例。如果您正苦於以下問題:Java DateFormat.getBestDateTimePattern方法的具體用法?Java DateFormat.getBestDateTimePattern怎麽用?Java DateFormat.getBestDateTimePattern使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.text.format.DateFormat的用法示例。


在下文中一共展示了DateFormat.getBestDateTimePattern方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getBestDateTimePattern

import android.text.format.DateFormat; //導入方法依賴的package包/類
/**
 * Creates the best date-time pattern for the specified locale using the given skeleton. This
 * method works by calling {@link DateFormat#getBestDateTimePattern(Locale, String)} on API 18
 * and up, while returning a static pattern on lower API levels.
 *
 * @param context  the context that will be used on pre API 18 devices to guess the format
 * @param locale   the locale to be used as the formatting base (it might be ignored on pre API 18)
 * @param skeleton the skeleton for the pattern guesser / native method
 * @return A pattern that should be usable by formatters.
 * @see DateFormat
 * @see java.text.SimpleDateFormat
 */
public static String getBestDateTimePattern(Context context, Locale locale, String skeleton) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return DateFormat.getBestDateTimePattern(locale, skeleton);
    } else {
        switch (skeleton) {
            case SKELETON_Hm:
                return context.getString(R.string.datetime_Hm);
            case SKELETON_hm:
                return context.getString(R.string.datetime_hm);
            case SKELETON_EMMMd:
                return context.getString(R.string.datetime_EMMMd);
            case SKELETON_EMMMMdy:
                return context.getString(R.string.datetime_EMMMMdy);
            case SKELETON_MMMMy:
                return context.getString(R.string.datetime_MMMMy);

            default:
                throw new UnsupportedOperationException();
        }
    }
}
 
開發者ID:Gericop,項目名稱:DateTimePicker,代碼行數:34,代碼來源:DateFormatFix.java

示例2: getChangeSummary

import android.text.format.DateFormat; //導入方法依賴的package包/類
/**
 * Produce a summary of the Zen mode change to be read aloud as TTS.
 */
private CharSequence getChangeSummary(int mode, int minutes) {
    int indefinite = -1;
    int byMinute = -1;
    int byHour = -1;
    int byTime = -1;

    switch (mode) {
        case Global.ZEN_MODE_ALARMS:
            indefinite = R.string.zen_mode_summary_alarms_only_indefinite;
            byMinute = R.plurals.zen_mode_summary_alarms_only_by_minute;
            byHour = R.plurals.zen_mode_summary_alarms_only_by_hour;
            byTime = R.string.zen_mode_summary_alarms_only_by_time;
            break;
        case Global.ZEN_MODE_OFF:
            indefinite = R.string.zen_mode_summary_always;
            break;
    };

    if (minutes < 0 || mode == Global.ZEN_MODE_OFF) {
        return getString(indefinite);
    }

    long time = System.currentTimeMillis() + minutes * MINUTES_MS;
    String skeleton = DateFormat.is24HourFormat(this, UserHandle.myUserId()) ? "Hm" : "hma";
    String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton);
    CharSequence formattedTime = DateFormat.format(pattern, time);
    Resources res = getResources();

    if (minutes < 60) {
        return res.getQuantityString(byMinute, minutes, minutes, formattedTime);
    } else if (minutes % 60 != 0) {
        return res.getString(byTime, formattedTime);
    } else {
        int hours = minutes / 60;
        return res.getQuantityString(byHour, hours, hours, formattedTime);
    }
}
 
開發者ID:ric96,項目名稱:lineagex86,代碼行數:41,代碼來源:ZenModeVoiceActivity.java

示例3: getLocalizedPattern

import android.text.format.DateFormat; //導入方法依賴的package包/類
private static String getLocalizedPattern(String template, Locale locale) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
    return DateFormat.getBestDateTimePattern(locale, template);
  } else {
    return new SimpleDateFormat(template, locale).toLocalizedPattern();
  }
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:8,代碼來源:DateUtils.java

示例4: getMonthAndYearString

import android.text.format.DateFormat; //導入方法依賴的package包/類
@NonNull
private String getMonthAndYearString() {
    Locale locale = Locale.getDefault();
    String pattern = "MMMM yyyy";

    if(Build.VERSION.SDK_INT < 18) pattern = getContext().getResources().getString(R.string.mdtp_date_v1_monthyear);
    else pattern = DateFormat.getBestDateTimePattern(locale, pattern);

    SimpleDateFormat formatter = new SimpleDateFormat(pattern, locale);
    formatter.applyLocalizedPattern(pattern);
    mStringBuilder.setLength(0);
    return formatter.format(mCalendar.getTime());
}
 
開發者ID:LingjuAI,項目名稱:AssistantBySDK,代碼行數:14,代碼來源:MonthView.java

示例5: getTimeSeparator

import android.text.format.DateFormat; //導入方法依賴的package包/類
/**
 * @return The time separator used in the user's locale.
 */
static String getTimeSeparator(@NonNull Context context, boolean is24Hour) {
    // The time separator is defined in the Unicode CLDR and cannot be supposed to be ":".
    // See http://unicode.org/cldr/trac/browser/trunk/common/main.
    if (Build.VERSION.SDK_INT >= 18) {
        // We pass the correct "skeleton" depending on 12 or 24 hours view and then extract the
        // separator, which is the character just after the hour marker in the returned pattern.
        final String bestDateTimePattern = DateFormat.getBestDateTimePattern(
                getPrimaryLocale(context), (is24Hour) ? "Hm" : "hm");
        final String separatorText;
        // See http://www.unicode.org/reports/tr35/tr35-dates.html for hour formats
        final char[] hourFormats = {'H', 'h', 'K', 'k'};
        int hIndex = lastIndexOfAny(bestDateTimePattern, hourFormats);
        if (hIndex == -1) {
            // Default case
            separatorText = ":";
        } else {
            separatorText = Character.toString(bestDateTimePattern.charAt(hIndex + 1));
        }
        return separatorText;
    } else {
        // Format a dummy time string in 24-hour time, then iterate through the string until
        // we find a non-digit character.
        final String formatted24HourTime = DateUtils.formatDateTime(context,
                System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_24HOUR);
        for (int i = 0; i < formatted24HourTime.length(); i++) {
            final char c = formatted24HourTime.charAt(i);
            if (!Character.isDigit(c)) {
                return Character.toString(c);
            }
        }
        return "";
    }
}
 
開發者ID:philliphsu,項目名稱:NumberPadTimePicker,代碼行數:37,代碼來源:DateTimeFormatUtils.java

示例6: isAmPmWrittenBeforeTime

import android.text.format.DateFormat; //導入方法依賴的package包/類
/**
 * @return {@code true} if the AM or PM label is written before the time
 *         in the user's locale.
 */
static boolean isAmPmWrittenBeforeTime(@NonNull Context context) {
    if (Build.VERSION.SDK_INT >= 18) {
        final String dateTimePattern = DateFormat.getBestDateTimePattern(
                getPrimaryLocale(context), "hm");
        return dateTimePattern.startsWith("a");
    } else {
        // Format a dummy time string in 12-hour time, then check if the string
        // starts with a non-digit character. This should be the AM/PM label.
        final String formatted12HourTime = DateUtils.formatDateTime(context,
                System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_12HOUR);
        return !Character.isDigit(formatted12HourTime.charAt(0));
    }
}
 
開發者ID:philliphsu,項目名稱:NumberPadTimePicker,代碼行數:18,代碼來源:DateTimeFormatUtils.java

示例7: onCreate

import android.text.format.DateFormat; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_concert_details);
    ButterKnife.bind(this);

    String concertId = getIntent().getStringExtra(EXTRA_CONCERT_ID);

    //noinspection unchecked
    presenter = (ConcertDetailsPresenter) getLastCustomNonConfigurationInstance();

    if (presenter == null) {
        presenter = new ConcertDetailsPresenter.Builder(
                RepositoryProvider.provideRepository(getApplicationContext()),
                DefaultSchedulerProvider.getInstance())
                .concertId(concertId)
                .build();
        presenter.sendUiEvent(LoadConcertEvent.INSTANCE);
    }

    toolbar.setNavigationIcon(R.drawable.ic_menu_back);
    toolbar.setNavigationOnClickListener(v -> onBackPressed());

    dateFormatString = DateFormat.getBestDateTimePattern(Locale.getDefault(), "yyyyMMMMdEEEE");
    imageLoader = Injection.provideInjection().provideImageLoader();
    openSiteView.setOnClickListener(v -> presenter.sendUiEvent(SiteClickEvent.INSTANCE));
}
 
開發者ID:andreybgm,項目名稱:gigreminder,代碼行數:29,代碼來源:ConcertDetailsActivity.java

示例8: ListViewHolder

import android.text.format.DateFormat; //導入方法依賴的package包/類
public ListViewHolder(View itemView) {
    super(itemView);

    ButterKnife.bind(this, itemView);

    thisYearDateFormat = DateFormat.getBestDateTimePattern(Locale.getDefault(), "MMMdEEE");
    anotherYearDateFormat = DateFormat.getBestDateTimePattern(Locale.getDefault(),
            "yyyyMMMdEEE");
}
 
開發者ID:andreybgm,項目名稱:gigreminder,代碼行數:10,代碼來源:ListViewHolder.java


注:本文中的android.text.format.DateFormat.getBestDateTimePattern方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。