当前位置: 首页>>代码示例>>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;未经允许,请勿转载。