Linguaggio

DateTimePatternGenerator.GetBestPattern Metodo

Definizione

Overload

Nome Descrizione
GetBestPattern(String, DateTimePatternMatchOptions)

Restituisce il modello migliore corrispondente allo scheletro di input.

GetBestPattern(String)

Restituisce il modello migliore corrispondente allo scheletro di input.

GetBestPattern(String, DateTimePatternMatchOptions)

Restituisce il modello migliore corrispondente allo scheletro di input.

[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

Parametri

skeleton
String

Lo scheletro è un modello contenente solo i campi delle variabili. Ad esempio, "MMMdd" e "mmhh" sono scheletri.

options
DateTimePatternMatchOptions

MATCH_xxx opzioni per forzare la lunghezza dei campi specificati nel modello restituito in modo che corrispondano a quelli presenti nello scheletro (quando ciò non avviene altrimenti). Per il comportamento predefinito, usare MATCH_NO_OPTIONS.

Valori restituiti

Modello ottimale che corrisponde allo scheletro di input (e alle opzioni).

Attributi

Commenti

Restituisce il modello migliore corrispondente allo scheletro di input. È garantito che tutti i campi nello scheletro.

per android.icu.text.DateTimePatternGenerator.getBestPattern(java.lang.String, int).

Le parti di questa pagina sono modifiche basate sul lavoro creato e condiviso dalla e usati in base ai termini descritti in Creative License 2.5 Attribution License.

Si applica a

GetBestPattern(String)

Restituisce il modello migliore corrispondente allo scheletro di input.

[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

Parametri

skeleton
String

Lo scheletro è un modello contenente solo i campi delle variabili. Ad esempio, "MMMdd" e "mmhh" sono scheletri.

Valori restituiti

Modello migliore che corrisponde allo scheletro di input.

Attributi

Commenti

Restituisce il modello migliore corrispondente allo scheletro di input. È garantito che tutti i campi nello scheletro.

Codice di esempio:

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

Informazioni di riferimento su Android per android.icu.text.DateTimePatternGenerator.getBestPattern.

Le parti di questa pagina sono modifiche basate sul lavoro creato e condiviso dalla e usati in base ai termini descritti in Creative License 2.5 Attribution License.

Si applica a