Language

DateIntervalFormat.GetInstance Method

Definition

Overloads

Name Description
GetInstance(String, Locale, DateIntervalInfo)

Construct a DateIntervalFormat from skeleton a DateIntervalInfo, and the given locale.

GetInstance(String, ULocale, DateIntervalInfo)

Construct a DateIntervalFormat from skeleton a DateIntervalInfo, and the given locale.

GetInstance(String, Locale)

Construct a DateIntervalFormat from skeleton and a given locale.

GetInstance(String, DateIntervalInfo)

Construct a DateIntervalFormat from skeleton DateIntervalInfo, and the default FORMAT locale.

GetInstance(String)

Construct a DateIntervalFormat from skeleton and the default FORMAT locale.

GetInstance(String, ULocale)

Construct a DateIntervalFormat from skeleton and a given locale.

GetInstance(String, Locale, DateIntervalInfo)

Construct a DateIntervalFormat from skeleton a DateIntervalInfo, and the given locale.

[Android.Runtime.Register("getInstance", "(Ljava/lang/String;Ljava/util/Locale;Landroid/icu/text/DateIntervalInfo;)Landroid/icu/text/DateIntervalFormat;", "", ApiSince=24)]
public static Android.Icu.Text.DateIntervalFormat? GetInstance(string? skeleton, Java.Util.Locale? locale, Android.Icu.Text.DateIntervalInfo? dtitvinf);
[<Android.Runtime.Register("getInstance", "(Ljava/lang/String;Ljava/util/Locale;Landroid/icu/text/DateIntervalInfo;)Landroid/icu/text/DateIntervalFormat;", "", ApiSince=24)>]
static member GetInstance : string * Java.Util.Locale * Android.Icu.Text.DateIntervalInfo -> Android.Icu.Text.DateIntervalFormat

Parameters

skeleton
String

the skeleton on which interval format based.

locale
Locale

the given locale

dtitvinf
DateIntervalInfo

the DateIntervalInfo object to be adopted.

Returns

a date time interval formatter.

Attributes

Remarks

Construct a DateIntervalFormat from skeleton a DateIntervalInfo, and the given locale. This is a convenient override of getInstance(String skeleton, ULocale locale, DateIntervalInfo dtitvinf)

Example code:

final Date date[] = {
        new GregorianCalendar(2007,9,10,10,10,10).getTime(),
        new GregorianCalendar(2007,10,10,10,10,10).getTime(),
        new GregorianCalendar(2007,10,10,22,10,10).getTime(),
};
final DateInterval dtitv[] = {
        new DateInterval(date[0].getTime(),date[1].getTime()),
        new DateInterval(date[1].getTime(),date[2].getTime()),
};
final String [] skeletons = {
        DateFormat.YEAR_ABBR_MONTH_DAY,
        DateFormat.HOUR24_MINUTE,
};
System.out.printf("%-15s%-35s%-35s%-45s%-35s\n", "Skeleton", "from","to", "Date Interval in en_US", "Date Interval in Ja");
// Create an empty DateIntervalInfo object
DateIntervalInfo dtitvinf = new DateIntervalInfo(ULocale.ENGLISH);
// Set Date Time internal pattern for MONTH, DAY_OF_MONTH, HOUR_OF_DAY
dtitvinf.setIntervalPattern("yMMMd", Calendar.MONTH, "y 'Diff' MMM d --- MMM d");
dtitvinf.setIntervalPattern("Hm", Calendar.HOUR_OF_DAY, "yyyy MMM d HH:mm ~ HH:mm");
// Set fallback interval pattern
dtitvinf.setFallbackIntervalPattern("{0} ~~~ {1}");
// Get the DateIntervalFormat with the custom pattern
for (String skeleton:skeletons){
    for (int i=0;i<2;i++) {
        System.out.printf("%-15s%-35s%-35s", skeleton,date[i].toString(), date[i+1].toString());
        DateIntervalFormat dtitvfmtEn = DateIntervalFormat.getInstance(skeleton,ULocale.ENGLISH,dtitvinf);
        DateIntervalFormat dtitvfmtJa = DateIntervalFormat.getInstance(skeleton,ULocale.JAPANESE,dtitvinf);
        System.out.printf("%-45s%-35s\n", dtitvfmtEn.format(dtitv[i]),dtitvfmtJa.format(dtitv[i]));
    }
}
/** output of the sample code:
 *************************************************************************************************************************************************************************
  Skeleton       from                               to                                 Date Interval in en_US                       Date Interval in Ja
  yMMMd          Wed Oct 10 10:10:10 EDT 2007       Sat Nov 10 10:10:10 EST 2007       2007 Diff Oct 10 --- Nov 10                  2007 Diff 10\u6708 10 --- 11\u6708 10
  yMMMd          Sat Nov 10 10:10:10 EST 2007       Sat Nov 10 22:10:10 EST 2007       Nov 10, 2007                                 2007\u5e7411\u670810\u65e5
  Hm             Wed Oct 10 10:10:10 EDT 2007       Sat Nov 10 10:10:10 EST 2007       10/10/2007, 10:10 ~~~ 11/10/2007, 10:10      2007/10/10 10:10 ~~~ 2007/11/10 10:10
  Hm             Sat Nov 10 10:10:10 EST 2007       Sat Nov 10 22:10:10 EST 2007       2007 Nov 10 10:10 ~ 22:10                    2007 11\u6708 10 10:10 ~ 22:10
 *************************************************************************************************************************************************************************/

Android reference for android.icu.text.DateIntervalFormat.getInstance.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

GetInstance(String, ULocale, DateIntervalInfo)

Construct a DateIntervalFormat from skeleton a DateIntervalInfo, and the given locale.

[Android.Runtime.Register("getInstance", "(Ljava/lang/String;Landroid/icu/util/ULocale;Landroid/icu/text/DateIntervalInfo;)Landroid/icu/text/DateIntervalFormat;", "", ApiSince=24)]
public static Android.Icu.Text.DateIntervalFormat? GetInstance(string? skeleton, Android.Icu.Util.ULocale? locale, Android.Icu.Text.DateIntervalInfo? dtitvinf);
[<Android.Runtime.Register("getInstance", "(Ljava/lang/String;Landroid/icu/util/ULocale;Landroid/icu/text/DateIntervalInfo;)Landroid/icu/text/DateIntervalFormat;", "", ApiSince=24)>]
static member GetInstance : string * Android.Icu.Util.ULocale * Android.Icu.Text.DateIntervalInfo -> Android.Icu.Text.DateIntervalFormat

Parameters

skeleton
String

the skeleton on which interval format based.

locale
ULocale

the given locale

dtitvinf
DateIntervalInfo

the DateIntervalInfo object to be adopted.

Returns

a date time interval formatter.

Attributes

Remarks

Construct a DateIntervalFormat from skeleton a DateIntervalInfo, and the given locale.

In this factory method, user provides its own date interval pattern information, instead of using those pre-defined data in resource file. This factory method is for powerful users who want to provide their own interval patterns.

There are pre-defined skeleton in DateFormat, such as MONTH_DAY, YEAR_MONTH_WEEKDAY_DAY etc.

Those skeletons have pre-defined interval patterns in resource files. Users are encouraged to use them. For example: DateIntervalFormat.getInstance(DateFormat.MONTH_DAY, false, loc,itvinf);

the DateIntervalInfo provides the interval patterns.

User are encouraged to set default interval pattern in DateIntervalInfo as well, if they want to set other interval patterns ( instead of reading the interval patterns from resource files). When the corresponding interval pattern for a largest calendar different field is not found ( if user not set it ), interval format fallback to the default interval pattern. If user does not provide default interval pattern, it fallback to "{date0} - {date1}"

Java documentation for android.icu.text.DateIntervalFormat.getInstance(java.lang.String, android.icu.util.ULocale, android.icu.text.DateIntervalInfo).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

GetInstance(String, Locale)

Construct a DateIntervalFormat from skeleton and a given locale.

[Android.Runtime.Register("getInstance", "(Ljava/lang/String;Ljava/util/Locale;)Landroid/icu/text/DateIntervalFormat;", "", ApiSince=24)]
public static Android.Icu.Text.DateIntervalFormat? GetInstance(string? skeleton, Java.Util.Locale? locale);
[<Android.Runtime.Register("getInstance", "(Ljava/lang/String;Ljava/util/Locale;)Landroid/icu/text/DateIntervalFormat;", "", ApiSince=24)>]
static member GetInstance : string * Java.Util.Locale -> Android.Icu.Text.DateIntervalFormat

Parameters

skeleton
String

the skeleton on which interval format based.

locale
Locale

the given locale

Returns

a date time interval formatter.

Attributes

Remarks

Construct a DateIntervalFormat from skeleton and a given locale. This is a convenient override of getInstance(String skeleton, ULocale locale)

Example code:

import java.util.Date;

import android.icu.text.DateFormat;
import android.icu.text.DateIntervalFormat;
import android.icu.text.DateIntervalInfo;
import android.icu.util.Calendar;
import android.icu.util.DateInterval;
import android.icu.util.GregorianCalendar;
import android.icu.util.ULocale;
...
final Date date[] = {
        new GregorianCalendar(2007,10,10,10,10,10).getTime(),
        new GregorianCalendar(2008,10,10,10,10,10).getTime(),
        new GregorianCalendar(2008,11,10,10,10,10).getTime(),
        new GregorianCalendar(2008,11,10,15,10,10).getTime(),
};
final DateInterval dtitv[] = {
        new DateInterval(date[0].getTime(),date[1].getTime()),
        new DateInterval(date[1].getTime(),date[2].getTime()),
        new DateInterval(date[2].getTime(),date[3].getTime()),
};
final String [] skeletons = {
        DateFormat.YEAR_ABBR_MONTH_DAY,
        DateFormat.MONTH_DAY,
        DateFormat.HOUR_MINUTE,
};
System.out.printf("%-15s%-35s%-35s%-35s%-35s\n", "Skeleton", "from","to","Date Interval in en_US", "Date Interval in Ja");
int i=0;
for (String skeleton:skeletons) {
    System.out.printf("%-15s%-35s%-35s", skeleton,date[i].toString(), date[i+1].toString());
    DateIntervalFormat dtitvfmtEn = DateIntervalFormat.getInstance(skeleton, ULocale.ENGLISH);
    DateIntervalFormat dtitvfmtJa = DateIntervalFormat.getInstance(skeleton, ULocale.JAPANESE);
    System.out.printf("%-35s%-35s\n", dtitvfmtEn.format(dtitv[i]),dtitvfmtJa.format(dtitv[i]));
    i++;
}
/** output of the sample code:
 *********************************************************************************************************************************************************
 Skeleton       from                               to                                 Date Interval in en_US             Date Interval in Ja
 yMMMd          Sat Nov 10 10:10:10 EST 2007       Mon Nov 10 10:10:10 EST 2008       Nov 10, 2007 \u2013 Nov 10, 2008        2007\u5e7411\u670810\u65e5\uff5e2008\u5e7411\u670810\u65e5
 MMMMd          Mon Nov 10 10:10:10 EST 2008       Wed Dec 10 10:10:10 EST 2008       November 10 \u2013 December 10          11\u670810\u65e5\uff5e12\u670810\u65e5
 jm             Wed Dec 10 10:10:10 EST 2008       Wed Dec 10 15:10:10 EST 2008       10:10 AM \u2013 3:10 PM                 10:10\uff5e15:10
 *********************************************************************************************************************************************************/

Android reference for android.icu.text.DateIntervalFormat.getInstance.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

GetInstance(String, DateIntervalInfo)

Construct a DateIntervalFormat from skeleton DateIntervalInfo, and the default FORMAT locale.

[Android.Runtime.Register("getInstance", "(Ljava/lang/String;Landroid/icu/text/DateIntervalInfo;)Landroid/icu/text/DateIntervalFormat;", "", ApiSince=24)]
public static Android.Icu.Text.DateIntervalFormat? GetInstance(string? skeleton, Android.Icu.Text.DateIntervalInfo? dtitvinf);
[<Android.Runtime.Register("getInstance", "(Ljava/lang/String;Landroid/icu/text/DateIntervalInfo;)Landroid/icu/text/DateIntervalFormat;", "", ApiSince=24)>]
static member GetInstance : string * Android.Icu.Text.DateIntervalInfo -> Android.Icu.Text.DateIntervalFormat

Parameters

skeleton
String

the skeleton on which interval format based.

dtitvinf
DateIntervalInfo

the DateIntervalInfo object to be adopted.

Returns

a date time interval formatter.

Attributes

Remarks

Construct a DateIntervalFormat from skeleton DateIntervalInfo, and the default FORMAT locale.

This is a convenient override of getInstance(String skeleton, ULocale locale, DateIntervalInfo dtitvinf) with the locale value as default FORMAT locale.

Java documentation for android.icu.text.DateIntervalFormat.getInstance(java.lang.String, android.icu.text.DateIntervalInfo).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

GetInstance(String)

Construct a DateIntervalFormat from skeleton and the default FORMAT locale.

[Android.Runtime.Register("getInstance", "(Ljava/lang/String;)Landroid/icu/text/DateIntervalFormat;", "", ApiSince=24)]
public static Android.Icu.Text.DateIntervalFormat? GetInstance(string? skeleton);
[<Android.Runtime.Register("getInstance", "(Ljava/lang/String;)Landroid/icu/text/DateIntervalFormat;", "", ApiSince=24)>]
static member GetInstance : string -> Android.Icu.Text.DateIntervalFormat

Parameters

skeleton
String

the skeleton on which interval format based.

Returns

a date time interval formatter.

Attributes

Remarks

Construct a DateIntervalFormat from skeleton and the default FORMAT locale.

This is a convenient override of getInstance(String skeleton, ULocale locale) with the value of locale as default FORMAT locale.

Java documentation for android.icu.text.DateIntervalFormat.getInstance(java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

GetInstance(String, ULocale)

Construct a DateIntervalFormat from skeleton and a given locale.

[Android.Runtime.Register("getInstance", "(Ljava/lang/String;Landroid/icu/util/ULocale;)Landroid/icu/text/DateIntervalFormat;", "", ApiSince=24)]
public static Android.Icu.Text.DateIntervalFormat? GetInstance(string? skeleton, Android.Icu.Util.ULocale? locale);
[<Android.Runtime.Register("getInstance", "(Ljava/lang/String;Landroid/icu/util/ULocale;)Landroid/icu/text/DateIntervalFormat;", "", ApiSince=24)>]
static member GetInstance : string * Android.Icu.Util.ULocale -> Android.Icu.Text.DateIntervalFormat

Parameters

skeleton
String

the skeleton on which interval format based.

locale
ULocale

the given locale

Returns

a date time interval formatter.

Attributes

Remarks

Construct a DateIntervalFormat from skeleton and a given locale.

In this factory method, the date interval pattern information is load from resource files. Users are encouraged to created date interval formatter this way and to use the pre-defined skeleton macros.

There are pre-defined skeletons in DateFormat, such as MONTH_DAY, YEAR_MONTH_WEEKDAY_DAY etc.

Those skeletons have pre-defined interval patterns in resource files. Users are encouraged to use them. For example: DateIntervalFormat.getInstance(DateFormat.MONTH_DAY, false, loc);

The given Locale provides the interval patterns. For example, for en_GB, if skeleton is YEAR_ABBR_MONTH_WEEKDAY_DAY, which is "yMMMEEEd", the interval patterns defined in resource file to above skeleton are: "EEE, d MMM, yyyy - EEE, d MMM, yyyy" for year differs, "EEE, d MMM - EEE, d MMM, yyyy" for month differs, "EEE, d - EEE, d MMM, yyyy" for day differs,

Java documentation for android.icu.text.DateIntervalFormat.getInstance(java.lang.String, android.icu.util.ULocale).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to