DateTimePatternGenerator.GetBestPattern Método

Definição

Sobrecargas

Nome Description
GetBestPattern(String, DateTimePatternMatchOptions)

Retorne o melhor padrão correspondente ao esqueleto de entrada.

GetBestPattern(String)

Retorne o melhor padrão correspondente ao esqueleto de entrada.

GetBestPattern(String, DateTimePatternMatchOptions)

Retorne o melhor padrão correspondente ao esqueleto de entrada.

[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

Parâmetros

skeleton
String

O esqueleto é um padrão que contém apenas os campos variáveis. Por exemplo, "MMMdd" e "mmhh" são esqueletos.

options
DateTimePatternMatchOptions

MATCH_xxx opções para forçar o comprimento dos campos especificados no padrão retornado para corresponder àqueles no esqueleto (quando isso não aconteceria de outra forma). Para comportamento padrão, use MATCH_NO_OPTIONS.

Retornos

Melhor padrão que corresponde ao esqueleto de entrada (e opções).

Atributos

Comentários

Retorne o melhor padrão correspondente ao esqueleto de entrada. É garantido ter todos os campos no esqueleto.

Java documentação para android.icu.text.DateTimePatternGenerator.getBestPattern(java.lang.String, int).

Partes desta página são modificações baseadas no trabalho criado e compartilhado pelo Project Open Source do Open Source e usadas de acordo com os termos descritos na Creative Commons 2.5.

Aplica-se a

GetBestPattern(String)

Retorne o melhor padrão correspondente ao esqueleto de entrada.

[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

Parâmetros

skeleton
String

O esqueleto é um padrão que contém apenas os campos variáveis. Por exemplo, "MMMdd" e "mmhh" são esqueletos.

Retornos

Melhor padrão que corresponde ao esqueleto de entrada.

Atributos

Comentários

Retorne o melhor padrão correspondente ao esqueleto de entrada. É garantido ter todos os campos no esqueleto.

Exemplo de código:

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
 ************************************************************************************************************/

Referência do Android para android.icu.text.DateTimePatternGenerator.getBestPattern.

Partes desta página são modificações baseadas no trabalho criado e compartilhado pelo Project Open Source do Open Source e usadas de acordo com os termos descritos na Creative Commons 2.5.

Aplica-se a