Java Code Examples for java.time.format.DateTimeFormatterBuilder#getLocalizedDateTimePattern()

The following examples show how to use java.time.format.DateTimeFormatterBuilder#getLocalizedDateTimePattern() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InternalUtilities.java    From LGoodDatePicker with MIT License 6 votes vote down vote up
/**
 * generateDefaultFormatterBCE, This returns a default formatter for the specified locale, that
 * can be used for displaying or parsing BC dates. The formatter is generated from the default
 * FormatStyle.LONG formatter in the specified locale. The resulting format is intended to be
 * nearly identical to the default formatter used for AD dates.
 */
public static DateTimeFormatter generateDefaultFormatterBCE(Locale pickerLocale) {
    // This is verified to work for the following locale languages:
    // en, de, fr, pt, ru, it, nl, es, pl, da, ro, sv, zh.
    String displayFormatterBCPattern = DateTimeFormatterBuilder.getLocalizedDateTimePattern(
        FormatStyle.LONG, null, IsoChronology.INSTANCE, pickerLocale);
    displayFormatterBCPattern = displayFormatterBCPattern.replace("y", "u");
    // Note: We could have used DateUtilities.createFormatterFromPatternString(), which should
    // have the same formatter options as this line. We kept this code independent in case
    // anyone ever mistakenly changes that utility function.
    DateTimeFormatter displayFormatterBC = new DateTimeFormatterBuilder().parseLenient()
        .parseCaseInsensitive().appendPattern(displayFormatterBCPattern)
        .toFormatter(pickerLocale);
    // Get the local language as a string.
    String language = pickerLocale.getLanguage();
    // Override the format for the turkish locale to remove the name of the weekday.
    if ("tr".equals(language)) {
        displayFormatterBC = PickerUtilities.createFormatterFromPatternString(
            "dd MMMM uuuu", pickerLocale);
    }
    return displayFormatterBC;
}
 
Example 2
Source File: ComAdminImpl.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public DateTimeFormatter getDateTimeFormatter() {
	String dateTimeFormatPattern = DateTimeFormatterBuilder.getLocalizedDateTimePattern(FormatStyle.SHORT, FormatStyle.SHORT, IsoChronology.INSTANCE, getLocale());
	dateTimeFormatPattern = dateTimeFormatPattern.replaceFirst("y+", "yyyy").replaceFirst(", ", " ");
	DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateTimeFormatPattern, getLocale());
	dateTimeFormatter.withZone(TimeZone.getTimeZone(getAdminTimezone()).toZoneId());
	dateTimeFormatter.withResolverStyle(ResolverStyle.STRICT);
	return dateTimeFormatter;
}
 
Example 3
Source File: TestDateTimeFormatterBuilder.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
@UseDataProvider("localizedDateTimePatterns")
public void test_getLocalizedDateTimePattern(FormatStyle dateStyle, FormatStyle timeStyle,
        Chronology chrono, Locale locale, String expected) {
    String actual = DateTimeFormatterBuilder.getLocalizedDateTimePattern(dateStyle, timeStyle, chrono, locale);
    assertEquals("Pattern " + convertNonAscii(actual), actual, expected);
}
 
Example 4
Source File: ComAdminImpl.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public DateTimeFormatter getDateTimeFormatterWithSeconds() {
	String dateFormatPattern = DateTimeFormatterBuilder.getLocalizedDateTimePattern(FormatStyle.SHORT, FormatStyle.MEDIUM, IsoChronology.INSTANCE, getLocale());
	dateFormatPattern = dateFormatPattern.replaceFirst("y+", "yyyy").replaceFirst(", ", " ");
	DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateFormatPattern, getLocale());
	dateTimeFormatter.withZone(TimeZone.getTimeZone(getAdminTimezone()).toZoneId());
	dateTimeFormatter.withResolverStyle(ResolverStyle.STRICT);
	return dateTimeFormatter;
}
 
Example 5
Source File: TestDateTimeFormatterBuilder.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="localePatterns")
public void test_getLocalizedDateTimePattern(FormatStyle dateStyle, FormatStyle timeStyle,
        Chronology chrono, Locale locale, String expected) {
    String actual = DateTimeFormatterBuilder.getLocalizedDateTimePattern(dateStyle, timeStyle, chrono, locale);
    assertEquals(actual, expected, "Pattern " + convertNonAscii(actual));
}
 
Example 6
Source File: PDTFormatPatterns.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static String getPatternTime (@Nonnull final FormatStyle eStyle, @Nonnull final Locale aDisplayLocale)
{
  return DateTimeFormatterBuilder.getLocalizedDateTimePattern (null, eStyle, IsoChronology.INSTANCE, aDisplayLocale);
}
 
Example 7
Source File: TestDateTimeFormatterBuilder.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="localePatterns")
public void test_getLocalizedDateTimePattern(FormatStyle dateStyle, FormatStyle timeStyle,
        Chronology chrono, Locale locale, String expected) {
    String actual = DateTimeFormatterBuilder.getLocalizedDateTimePattern(dateStyle, timeStyle, chrono, locale);
    assertEquals(actual, expected, "Pattern " + convertNonAscii(actual));
}
 
Example 8
Source File: TestDateTimeFormatterBuilder.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=java.lang.NullPointerException.class)
public void test_getLocalizedLocaleNPE() {
    DateTimeFormatterBuilder.getLocalizedDateTimePattern(FormatStyle.SHORT, FormatStyle.SHORT, IsoChronology.INSTANCE, null);
}
 
Example 9
Source File: TestDateTimeFormatterBuilder.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=java.lang.NullPointerException.class)
public void test_getLocalizedChronoNPE() {
    DateTimeFormatterBuilder.getLocalizedDateTimePattern(FormatStyle.SHORT, FormatStyle.SHORT, null, Locale.US);
}
 
Example 10
Source File: TestDateTimeFormatterBuilder.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="localePatterns")
public void test_getLocalizedDateTimePattern(FormatStyle dateStyle, FormatStyle timeStyle,
        Chronology chrono, Locale locale, String expected) {
    String actual = DateTimeFormatterBuilder.getLocalizedDateTimePattern(dateStyle, timeStyle, chrono, locale);
    assertEquals(actual, expected, "Pattern " + convertNonAscii(actual));
}
 
Example 11
Source File: TestDateTimeFormatterBuilder.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="localePatterns")
public void test_getLocalizedDateTimePattern(FormatStyle dateStyle, FormatStyle timeStyle,
        Chronology chrono, Locale locale, String expected) {
    String actual = DateTimeFormatterBuilder.getLocalizedDateTimePattern(dateStyle, timeStyle, chrono, locale);
    assertEquals(actual, expected, "Pattern " + convertNonAscii(actual));
}
 
Example 12
Source File: TestDateTimeFormatterBuilder.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=java.lang.NullPointerException.class)
public void test_getLocalizedChronoNPE() {
    DateTimeFormatterBuilder.getLocalizedDateTimePattern(FormatStyle.SHORT, FormatStyle.SHORT, null, Locale.US);
}
 
Example 13
Source File: TestDateTimeFormatterBuilder.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=java.lang.NullPointerException.class)
public void test_getLocalizedChronoNPE() {
    DateTimeFormatterBuilder.getLocalizedDateTimePattern(FormatStyle.SHORT, FormatStyle.SHORT, null, Locale.US);
}
 
Example 14
Source File: TestDateTimeFormatterBuilder.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="localePatterns")
public void test_getLocalizedDateTimePattern(FormatStyle dateStyle, FormatStyle timeStyle,
        Chronology chrono, Locale locale, String expected) {
    String actual = DateTimeFormatterBuilder.getLocalizedDateTimePattern(dateStyle, timeStyle, chrono, locale);
    assertEquals(actual, expected, "Pattern " + convertNonAscii(actual));
}
 
Example 15
Source File: TestDateTimeFormatterBuilder.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=java.lang.NullPointerException.class)
public void test_getLocalizedLocaleNPE() {
    DateTimeFormatterBuilder.getLocalizedDateTimePattern(FormatStyle.SHORT, FormatStyle.SHORT, IsoChronology.INSTANCE, null);
}
 
Example 16
Source File: TestDateTimeFormatterBuilder.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=java.lang.NullPointerException.class)
public void test_getLocalizedLocaleNPE() {
    DateTimeFormatterBuilder.getLocalizedDateTimePattern(FormatStyle.SHORT, FormatStyle.SHORT, IsoChronology.INSTANCE, null);
}
 
Example 17
Source File: TestDateTimeFormatterBuilder.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=java.lang.NullPointerException.class)
public void test_getLocalizedLocaleNPE() {
    DateTimeFormatterBuilder.getLocalizedDateTimePattern(FormatStyle.SHORT, FormatStyle.SHORT, IsoChronology.INSTANCE, null);
}
 
Example 18
Source File: TestDateTimeFormatterBuilder.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="localePatterns")
public void test_getLocalizedDateTimePattern(FormatStyle dateStyle, FormatStyle timeStyle,
        Chronology chrono, Locale locale, String expected) {
    String actual = DateTimeFormatterBuilder.getLocalizedDateTimePattern(dateStyle, timeStyle, chrono, locale);
    assertEquals(actual, expected, "Pattern " + convertNonAscii(actual));
}
 
Example 19
Source File: TestDateTimeFormatterBuilder.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=java.lang.IllegalArgumentException.class)
public void test_getLocalizedDateTimePatternIAE() {
    DateTimeFormatterBuilder.getLocalizedDateTimePattern(null, null, IsoChronology.INSTANCE, Locale.US);
}
 
Example 20
Source File: TestDateTimeFormatterBuilder.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=java.lang.NullPointerException.class)
public void test_getLocalizedChronoNPE() {
    DateTimeFormatterBuilder.getLocalizedDateTimePattern(FormatStyle.SHORT, FormatStyle.SHORT, null, Locale.US);
}