DateTimePatternGenerator.GetBestPattern 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重载
| 名称 | 说明 |
|---|---|
| GetBestPattern(String, DateTimePatternMatchOptions) |
返回与输入框架匹配的最佳模式。 |
| GetBestPattern(String) |
返回与输入框架匹配的最佳模式。 |
GetBestPattern(String, DateTimePatternMatchOptions)
返回与输入框架匹配的最佳模式。
[Android.Runtime.Register("getBestPattern", "(Ljava/lang/String;I)Ljava/lang/String;", "GetGetBestPattern_Ljava_lang_String_IHandler", ApiSince=24)]
public virtual string? GetBestPattern(string? skeleton, Android.Icu.Text.DateTimePatternMatchOptions options);
[<Android.Runtime.Register("getBestPattern", "(Ljava/lang/String;I)Ljava/lang/String;", "GetGetBestPattern_Ljava_lang_String_IHandler", ApiSince=24)>]
abstract member GetBestPattern : string * Android.Icu.Text.DateTimePatternMatchOptions -> string
override this.GetBestPattern : string * Android.Icu.Text.DateTimePatternMatchOptions -> string
参数
- skeleton
- String
框架是仅包含变量字段的模式。 例如,“MMMdd”和“mmhh”是骨架。
- options
- DateTimePatternMatchOptions
MATCH_xxx选项,用于强制返回模式中的指定字段长度与骨架中的字段匹配(否则不会发生这种情况)。 对于默认行为,请使用MATCH_NO_OPTIONS。
返回
与输入框架(和选项)匹配的最佳模式。
- 特性
注解
返回与输入框架匹配的最佳模式。 保证在骨架中具有所有字段。
Java文档android.icu.text.DateTimePatternGenerator.getBestPattern(java.lang.String, int)。
本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。
适用于
GetBestPattern(String)
返回与输入框架匹配的最佳模式。
[Android.Runtime.Register("getBestPattern", "(Ljava/lang/String;)Ljava/lang/String;", "GetGetBestPattern_Ljava_lang_String_Handler", ApiSince=24)]
public virtual string? GetBestPattern(string? skeleton);
[<Android.Runtime.Register("getBestPattern", "(Ljava/lang/String;)Ljava/lang/String;", "GetGetBestPattern_Ljava_lang_String_Handler", ApiSince=24)>]
abstract member GetBestPattern : string -> string
override this.GetBestPattern : string -> string
参数
- skeleton
- String
框架是仅包含变量字段的模式。 例如,“MMMdd”和“mmhh”是骨架。
返回
与输入框架匹配的最佳模式。
- 特性
注解
返回与输入框架匹配的最佳模式。 保证在骨架中具有所有字段。
示例代码:
import java.util.Date;
import android.icu.text.DateFormat;
import android.icu.text.DateTimePatternGenerator;
import android.icu.text.SimpleDateFormat;
import android.icu.util.GregorianCalendar;
import android.icu.util.TimeZone;
import android.icu.util.ULocale;
...
final String[] skeletons = {
"yQQQQ", // year + full name of quarter, i.e., 4th quarter 1999
"yMMMM", // year + full name of month, i.e., October 1999
"MMMMd", // full name of month + day of the month, i.e., October 25
"hhmm", // 12-hour-cycle format, i.e., 1:32 PM
"jjmm" // preferred hour format for the given locale, i.e., 24-hour-cycle format for fr_FR
};
final ULocale[] locales = {
new ULocale ("en_US"),
new ULocale ("fr_FR"),
new ULocale ("zh_CN"),
};
DateTimePatternGenerator dtfg = null;
Date date= new GregorianCalendar(1999,9,13,23,58,59).getTime();
System.out.printf("%-20s%-35s%-35s%-35s\n\n", "Skeleton", "en_US", "fr_FR","zh_CN");
for (String skeleton:skeletons) {
System.out.printf("%-20s", skeleton);
for (ULocale locale:locales) {
// create a DateTimePatternGenerator instance for given locale
dtfg = DateTimePatternGenerator.getInstance(locale);
// use getBestPattern method to get the best pattern for the given skeleton
String pattern = dtfg.getBestPattern(skeleton);
// Constructs a SimpleDateFormat with the best pattern generated above and the given locale
SimpleDateFormat sdf = new SimpleDateFormat(pattern, locale);
// Get the format of the given date
System.out.printf("%-35s",sdf.format(date));
}
System.out.println("\n");
}
/** output of the sample code:
*************************************************************************************************************
Skeleton en_US fr_FR zh_CN
yQQQQ 4th quarter 1999 4e trimestre 1999 1999\u5e74\u7b2c\u56db\u5b63\u5ea6
yMMMM October 1999 octobre 1999 1999\u5e7410\u6708
MMMMd October 13 13 octobre 10\u670813\u65e5
hhmm 11:58 PM 11:58 PM \u4e0b\u534811:58
jjmm 11:58 PM 23:58 \u4e0b\u534811:58
**************************************************************************************************************/
// Use DateTime.getPatternInstance to produce the same Date/Time format with predefined constant field value
final String[] dtfskeleton = {
DateFormat.YEAR_QUARTER, // year + full name of quarter, i.e., 4th quarter 1999
DateFormat.YEAR_MONTH, // year + full name of month, i.e., October 1999
DateFormat.MONTH_DAY // full name of month + day of the month, i.e., October 25
};
System.out.printf("%-20s%-35s%-35s%-35s\n\n", "Skeleton", "en_US", "fr_FR","zh_CN");
for (String skeleton:dtfskeleton) {
System.out.printf("%-20s", skeleton);
for (ULocale locale:locales) {
// Use DateFormat.getPatternInstance to get the date/time format for the locale,
// and apply the format to the given date
String df=DateFormat.getPatternInstance(skeleton,locale).format(date);
System.out.printf("%-35s",df);
}
System.out.println("\n");
}
/** output of the sample code:
************************************************************************************************************
Skeleton en_US fr_FR zh_CN
yQQQQ 4th quarter 1999 4e trimestre 1999 1999\u5e74\u7b2c\u56db\u5b63\u5ea6
yMMMM October 1999 octobre 1999 1999\u5e7410\u6708
MMMMd October 13 13 octobre 10\u670813\u65e5
************************************************************************************************************/
Android 参考。android.icu.text.DateTimePatternGenerator.getBestPattern
本页的某些部分是根据 创建和共享的工作进行的修改,并根据 许可证中所述的条款使用。