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を使用します。
返品
入力スケルトン (およびオプション) に一致する最適なパターン。
- 属性
注釈
入力スケルトンに一致する最適なパターンを返します。 スケルトン内のすべてのフィールドが保証されます。
このページの一部は、によって作成および共有され、に記載されている条件に従って使用される作業に基づく変更です。
適用対象
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.icu.text.DateTimePatternGenerator.getBestPatternの Android リファレンス。
このページの一部は、によって作成および共有され、に記載されている条件に従って使用される作業に基づく変更です。